Google Pagespeed can convert RGB images to the YUV 4:2:0 colourspace. I would like to do the same in PHP using imagick.
Briefly, on why 4:2:0 is desired:
"This filter reduces the color sampling of jpeg images to 4:2:0. Human vision is much more sensitive to changes in brightness than changes in hue or saturation, and 4:2:0 color sampling allows us to keep brightness data while reducing the amount of hue and saturation data by 3/4. This can significantly reduce the image size while having only a small effect on perception."
I have tried to change the colorspace with imagemagick to YUV but it is not working at all well! The white backdrop goes to green and the rest of the colours are wrong, plus inverted luminance.
The following code is useless, but it shows a few of the things I have tried.
With the Google format created by mod_pagespeed the resultant images look fine in a browser. That is what I am hoping to achieve, images that are for the web.
$image_info = getimagesize($source_file);
$im = new Imagick();
$im->readImage($source_file);
$profiles = $im->getImageProfiles('*', false);
$has_icc_profile = (array_search('icc', $profiles) !== false);
if ($has_icc_profile === false) {
$icc_srgb = file_get_contents(Mage::getBaseDir('var') . DS . 'metodo' . DS . 'demo_data' . DS . 'AdobeRGB1998.icc');
$im->profileImage('icc', $icc_srgb);
unset($icc_srgb);
}
//$im->setImageColorspace(1);
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$im->setImageCompressionQuality(85);
//$im->stripImage();
$im->setImageColorspace(11);
$im->thumbnailImage($this->_imageSrcWidth, $this->_imageSrcHeight);
//$im->negateImage(false, Imagick::CHANNEL_ALL);
$im->stripImage();
$im->writeImage($fileName);