diff --git a/CImage.php b/CImage.php index c4a0f63..a31c962 100644 --- a/CImage.php +++ b/CImage.php @@ -2404,12 +2404,13 @@ class CImage * @param string $src of image. * @param string $dir as base directory where images are. * @param string $cache as base directory where to store images. + * @param string $iccFile filename of colorprofile. * @param boolean $useCache or not, default to always use cache. * * @return string | boolean false if no conversion else the converted * filename. */ - public function convert2sRGBColorSpace($src, $dir, $cache, $useCache = true) + public function convert2sRGBColorSpace($src, $dir, $cache, $iccFile, $useCache = true) { if ($this->verbose) { $this->log("# Converting image to sRGB colorspace."); @@ -2450,10 +2451,8 @@ class CImage if ($colorspace != Imagick::COLORSPACE_SRGB || $hasICCProfile) { $this->log(" Converting to sRGB."); - /* - $icc_rgb = file_get_contents('/path/to/icc/SomeRGBProfile.icc'); - $image->profileImage('icc', $icc_rgb); - */ + $sRGBicc = file_get_contents($iccFile); + $image->profileImage('icc', $sRGBicc); $image->transformImageColorspace(Imagick::COLORSPACE_SRGB); $image->writeImage($this->cacheFileName); diff --git a/REVISION.md b/REVISION.md index 75aab55..69f6eae 100644 --- a/REVISION.md +++ b/REVISION.md @@ -5,10 +5,10 @@ Revision history [![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master) -v0.7.7* (2015-10-21) +v0.7.7* (2015-10-24) ------------------------------------- -* Added conversion to sRGB using option `?srgb`, partly working. #120. +* Added conversion to sRGB using option `?srgb`. #120. * Change path in `webroot/htaccess` to make it work in current environment. diff --git a/icc/sRGB_IEC61966-2-1_black_scaled.icc b/icc/sRGB_IEC61966-2-1_black_scaled.icc new file mode 100644 index 0000000..a2c8645 Binary files /dev/null and b/icc/sRGB_IEC61966-2-1_black_scaled.icc differ diff --git a/test/CImageSRGBTest.php b/test/CImageSRGBTest.php index ba19f04..87f7128 100644 --- a/test/CImageSRGBTest.php +++ b/test/CImageSRGBTest.php @@ -7,7 +7,8 @@ class CImageSRGBTest extends \PHPUnit_Framework_TestCase { private $srgbDir = "srgb"; private $cache; - + private $srgbColorProfile = __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc'; + /** @@ -37,8 +38,9 @@ class CImageSRGBTest extends \PHPUnit_Framework_TestCase $filename = $img->convert2sRGBColorSpace( 'car.png', - IMAGE_PATH, - $this->cache + IMAGE_PATH, + $this->cache, + $this->srgbColorProfile ); if (class_exists("Imagick")) { @@ -62,7 +64,8 @@ class CImageSRGBTest extends \PHPUnit_Framework_TestCase $filename = $img->convert2sRGBColorSpace( 'car.jpg', IMAGE_PATH, - $this->cache + $this->cache, + $this->srgbColorProfile ); $this->assertFalse($filename); diff --git a/webroot/img.php b/webroot/img.php index f2f6fbf..14641bb 100644 --- a/webroot/img.php +++ b/webroot/img.php @@ -8,7 +8,7 @@ * */ -$version = "v0.7.7* (2015-10-21)"; +$version = "v0.7.7* (2015-10-24)"; @@ -976,10 +976,12 @@ if ($dummyImage === true) { * Prepare a sRGB version of the image and use it as source image. */ $srgbDirName = "/srgb"; -$srgbDir = getConfig('srgb_dir', $cachePath . $srgbDirName); -$srgb = getDefined('srgb', true, null); +$srgbDir = getConfig('srgb_dir', $cachePath . $srgbDirName); +$srgbDefault = getConfig('srgb_default', false); +$srgbColorProfile = getConfig('srgb_colorprofile', __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc'); +$srgb = getDefined('srgb', true, null); -if ($srgb) { +if ($srgb || $srgbDefault) { if (!is_writable($srgbDir)) { if (is_writable($cachePath)) { @@ -991,6 +993,7 @@ if ($srgb) { $srcImage, $imagePath, $srgbDir, + $srgbColorProfile, $useCache ); diff --git a/webroot/img/hamburger.jpg b/webroot/img/hamburger.jpg new file mode 100644 index 0000000..9ded88e Binary files /dev/null and b/webroot/img/hamburger.jpg differ diff --git a/webroot/img_config.php b/webroot/img_config.php index e84db44..ae555e4 100644 --- a/webroot/img_config.php +++ b/webroot/img_config.php @@ -122,6 +122,24 @@ return array( + /** + * Convert the image to srgb before processing. Saves the converted + * image in the sub cache dir. This option is default false but can + * be changed to default true to do this conversion for all images. + * This option requires PHP extension imagick and will silently fail + * if that is not installed. + * + * Default value: + * srgb_dir: $cachePath/srgb + * srgb_default: false + * srgb_colorprofile: __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc' + */ + //'srgb_dir' => __DIR__ . '/../cache/srgb/', + //'srgb_default' => false, + //'srgb_colorprofile' => __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc', + + + /** * A function (hook) can be called after img.php has processed all * configuration options and before processing the image using CImage.