Skip to content

Commit

Permalink
Merge pull request #15 from websightnl/colorspace
Browse files Browse the repository at this point in the history
Thank you!
  • Loading branch information
yurkinx authored Dec 8, 2016
2 parents 0d6d261 + 626da19 commit 2737b1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
/vendor/
24 changes: 15 additions & 9 deletions yii/image/drivers/Kohana/Image/Imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public function __construct($file)
$this->im = new Imagick;
$this->im->readImage($file);

// Force RGB colorspace if we are using non-RGB
$imageColorspace = $this->im->getImageColorspace();
if ($imageColorspace !== Imagick::COLORSPACE_RGB &&
$imageColorspace !== Imagick::COLORSPACE_SRGB
) {
$imageColorspace = Imagick::COLORSPACE_RGB;
}
if ($this->im->getImageColorspace() !== $imageColorspace) {
$this->im->transformImageColorspace($imageColorspace);
}
$this->im->setColorspace($imageColorspace);

if ( ! $this->im->getImageAlphaChannel())
{
// Force the image to have an alpha channel
Expand Down Expand Up @@ -206,9 +218,6 @@ protected function _do_reflection($height, $opacity, $fade_in)
// Force the background color to be transparent
// $image->setImageBackgroundColor(new ImagickPixel('transparent'));

// Match the colorspace between the two images before compositing
$image->setColorspace($this->im->getColorspace());

// Place the image and reflection into the container
if ($image->compositeImage($this->im, Imagick::COMPOSITE_SRC, 0, 0)
AND $image->compositeImage($reflection, Imagick::COMPOSITE_OVER, 0, $this->height))
Expand All @@ -231,6 +240,9 @@ protected function _do_watermark(Kohana_Image $image, $offset_x, $offset_y, $opa
// Convert the Image intance into an Imagick instance
$watermark = new Imagick;
$watermark->readImageBlob($image->render(), $image->file);
if ($this->im->getImageColorspace() !== $this->im->getColorspace()) {
$watermark->transformImageColorspace($this->im->getColorspace());
}

if ($watermark->getImageAlphaChannel() !== Imagick::ALPHACHANNEL_ACTIVATE)
{
Expand All @@ -244,9 +256,6 @@ protected function _do_watermark(Kohana_Image $image, $offset_x, $offset_y, $opa
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity / 100, Imagick::CHANNEL_ALPHA);
}

// Match the colorspace between the two images before compositing
// $watermark->setColorspace($this->im->getColorspace());

// Apply the watermark to the image
return $this->im->compositeImage($watermark, Imagick::COMPOSITE_DISSOLVE, $offset_x, $offset_y);
}
Expand All @@ -272,9 +281,6 @@ protected function _do_background($r, $g, $b, $opacity)
// NOTE: Using setImageOpacity will destroy current alpha channels!
$background->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity / 100, Imagick::CHANNEL_ALPHA);

// Match the colorspace between the two images before compositing
$background->setColorspace($this->im->getColorspace());

if ($background->compositeImage($this->im, Imagick::COMPOSITE_DISSOLVE, 0, 0))
{
// Replace the current image with the new image
Expand Down

0 comments on commit 2737b1e

Please sign in to comment.