Cropping the same image twice
Posted: 2009-12-26T13:18:03-07:00
I've just recently started to experiment with ImageMagick in PHP through the Imagick class, but stumbled across an oddity. I'm not sure whether it's a bug or not - it's probably my code - so I was wondering if someone can give me some insight in the situation.
As it stands, I need to crop a portion of an image and then on that cropped image crop it again. This in order to generate 2 thumbnails of a different size for file storage.
The problem is when I use the cropImage function on the imagemagick object the first time, it works like a charm. The second time however, I get 1x1 pixel results.
Short example
If I execute the code, the largethumbs are generated perfectly, but the smallthumbs are all 1x1. The $largeThumbWidth,$largeThumbHeight,$x,$y have values within the image range as the largethumbs are nicely generated, however if replace x and y with 0,0 the script works. I can go with the index up to the value of the width and height of the smallthumbnail, which is 75.
I do not want the coordinates to be 0,0 as some randomness is nice for the image gallery this is reaquired.
Does anyone see where I went wrong?
Thanks!
Ayame
As it stands, I need to crop a portion of an image and then on that cropped image crop it again. This in order to generate 2 thumbnails of a different size for file storage.
The problem is when I use the cropImage function on the imagemagick object the first time, it works like a charm. The second time however, I get 1x1 pixel results.
Short example
Code: Select all
$imagick = new Imagick($src_url);
// Do stuff to calculate x and y
$imagick->cropImage($largeThumbWidth,$largeThumbHeight,$x,$y);
$imagick->writeImage($dst_url .'largethumb'. $dst_filename . '.jpg');
// Now make the small thumb, I fixed the values to be sure
$imagick->cropImage(75,75,0,0);
$imagickthumb->writeImage($dst_url .'smallthumb'. $dst_filename . '.jpg');
I do not want the coordinates to be 0,0 as some randomness is nice for the image gallery this is reaquired.
Does anyone see where I went wrong?
Thanks!
Ayame