Page 1 of 1

Cropimage black & white output issue

Posted: 2014-08-04T15:32:28-07:00
by jamesmillerp
In some cases CropImage returns black&white image despite I've provided full color image.

Is this an issue with CropImage method or do I need to use some channels and filters before cropping?

Re: Cropimage black & white output issue

Posted: 2014-08-04T17:06:39-07:00
by fmw42
Best to provide you exact code and a link to the image that fails. Also what version of Imagick and Imagemagick are being used.

Re: Cropimage black & white output issue

Posted: 2014-08-05T11:27:14-07:00
by jamesmillerp
Hi fmw42,

Thanks for the quick reply.

Here is the code snippet that crops a tile from given image:

Code: Select all

$img = new Imagick();
$img->readImage($sourcePath);

$iW = $img->getImageWidth ();
$iH = $img->getImageHeight();

$bW = $iW/$xNum;
$bH = $iH/$yNum;

$cropWidth  = ($iW - $x*$bW);
$cropWidth  = $cropWidth  >= $bW ? $bW : $cropWidth;
$cropHeight = ($iH - $y*$bH);
$cropHeight = $cropHeight >= $bH ? $bH : $cropHeight;

$a = $x*$bW;
$b = $y*$bH;

$img->cropImage($cropWidth, $cropHeight, $x*$bW, $y*$bH);
$img->writeImage($destPath);
Here is the link of source file:
https://www.dropbox.com/s/2hd08td59s0hyjh/6707936.PNG
And this is the tile that I get before cropping the image:
https://www.dropbox.com/s/si07hygu972udwr/3_2-1-2.PNG

There is also one interesting thing. I crop the image into tiles and only this tile outputs black&white. Other tiles are in actual colors after cropping.

The version of:
imagick is 3.1.0RC1
imagemagick is ImageMagick 6.7.7-10 2014-03-08 Q16

Hope there is a solution for this issue.

Re: Cropimage black & white output issue

Posted: 2014-08-05T14:57:53-07:00
by fmw42
I am not an expert on Imagick. One of the Imagick users would likely have to reply. But you have
$a = $x*$bW;
$b = $y*$bH;

$img->cropImage($cropWidth, $cropHeight, $x*$bW, $y*$bH);
I do not know if you can do arithmetic as arguments. Why not try substituting $a and $b, which you compute just before.

Code: Select all

$a = $x*$bW;
$b = $y*$bH;

$img->cropImage($cropWidth, $cropHeight, [color=#FF0000]$a, $b[/color]);

Re: Cropimage black & white output issue

Posted: 2014-08-06T11:21:20-07:00
by jamesmillerp
Thanks, but actually that doesn't matter.

I've found the solution for the issue.

I've added this call before cropImage call.

Code: Select all

$img->setImageBackgroundColor('skyblue');
And it has fixed the issue with black&white output. Thanks anyway.