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?
Cropimage black & white output issue
-
- Posts: 3
- Joined: 2014-08-04T15:28:18-07:00
- Authentication code: 6789
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropimage black & white output issue
Best to provide you exact code and a link to the image that fails. Also what version of Imagick and Imagemagick are being used.
-
- Posts: 3
- Joined: 2014-08-04T15:28:18-07:00
- Authentication code: 6789
Re: Cropimage black & white output issue
Hi fmw42,
Thanks for the quick reply.
Here is the code snippet that crops a tile from given image:
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.
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);
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropimage black & white output issue
I am not an expert on Imagick. One of the Imagick users would likely have to reply. But you have
I do not know if you can do arithmetic as arguments. Why not try substituting $a and $b, which you compute just before.$a = $x*$bW;
$b = $y*$bH;
$img->cropImage($cropWidth, $cropHeight, $x*$bW, $y*$bH);
Code: Select all
$a = $x*$bW;
$b = $y*$bH;
$img->cropImage($cropWidth, $cropHeight, [color=#FF0000]$a, $b[/color]);
-
- Posts: 3
- Joined: 2014-08-04T15:28:18-07:00
- Authentication code: 6789
Re: Cropimage black & white output issue
Thanks, but actually that doesn't matter.
I've found the solution for the issue.
I've added this call before cropImage call.
And it has fixed the issue with black&white output. Thanks anyway.
I've found the solution for the issue.
I've added this call before cropImage call.
Code: Select all
$img->setImageBackgroundColor('skyblue');