Cropimage black & white output issue

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Locked
jamesmillerp
Posts: 3
Joined: 2014-08-04T15:28:18-07:00
Authentication code: 6789

Cropimage black & white output issue

Post 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?

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropimage black & white output issue

Post 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.

jamesmillerp
Posts: 3
Joined: 2014-08-04T15:28:18-07:00
Authentication code: 6789

Re: Cropimage black & white output issue

Post 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.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropimage black & white output issue

Post 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]);

jamesmillerp
Posts: 3
Joined: 2014-08-04T15:28:18-07:00
Authentication code: 6789

Re: Cropimage black & white output issue

Post 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.

Locked