mirror of
https://github.com/mosbth/cimage.git
synced 2025-07-31 05:30:09 +02:00
Added conversion to sRGB using option ?srgb. #120.
This commit is contained in:
@@ -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);
|
||||
|
@@ -5,10 +5,10 @@ Revision history
|
||||
[](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.
|
||||
|
||||
|
||||
|
BIN
icc/sRGB_IEC61966-2-1_black_scaled.icc
Normal file
BIN
icc/sRGB_IEC61966-2-1_black_scaled.icc
Normal file
Binary file not shown.
@@ -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);
|
||||
|
@@ -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
|
||||
);
|
||||
|
||||
|
BIN
webroot/img/hamburger.jpg
Normal file
BIN
webroot/img/hamburger.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 517 KiB |
@@ -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.
|
||||
|
Reference in New Issue
Block a user