Crop Bug Found!

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
MGSteve

Crop Bug Found!

Post by MGSteve » 2009-03-24T19:14:21-07:00

No, its not a discussion about a pest for wheat, but very odd behaviour with MagickCropImage.

I've got a JPG which is loaded into a MW handle and is 800x575. It needs to be 800x574, so I use this command to criop the line off...

MagickCropImage($mwimage,800,574,0,1);

And for some reason the output is 800x563.

I've done a bit of digging around and I believe its definitely a bug. If you open the file, call the crop function then it works fine. However, this particular file has a lot of operations done on it before it calls the crop function.

I've just spent 30 mins tracking every MW call made and you can easily recreate this bug by doing the following..

downloading this file:
http://www.ukwebsystems.com/inc/0002/im ... master.jpg

& running this code...

Code: Select all

<?php
      
  $Master = 'master.jpg';
  $Production = 'production.jpg'; // Will be created
  $Proof = 'proof.jpg'; // Will be created

  $hFile = NewMagickWand();
  MagickReadImage($hFile,$Master);

  MagickResizeImage($hFile,3355,2514,MW_QuadraticFilter,1.0);
  MagickCropImage($hFile,3355,2410,0,52);
  MagickSetCompressionQuality($hFile,95);
  MagickWriteImage($hFile,$Production);
  MagickResizeImage($hFile,800,575,MW_QuadraticFilter,1.0);

  // Image height is 575
  MagickCropImage($hFile,800,574,0,1);
  // Image height is 563!

  $ImgH = MagickGetImageHeight($hFile); // $ImgH is now 563

  MagickWriteImage($hFile,$Proof);

?>
Interestingly if you remove the earlier call to MagickCropImage the image is then cropped correctly to 574.

Is there somewhere I should repost this to attract a developer's attention!

In the mean time as a work around, if you save the file before the last crop and then reopen it again and then crop it, its fine.

It just appears to be if you crop the same image twice it doesn't work.

el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Crop Bug Found!

Post by el_supremo » 2009-03-24T20:19:59-07:00

Try adding
MagickResetImagePage($hfile,"0x0+0+0");
after the first crop. This will remove any virtual page info which may be interfering with the second crop.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

MGSteve

Re: Crop Bug Found!

Post by MGSteve » 2009-03-25T03:46:01-07:00

el_supremo wrote:Try adding
MagickResetImagePage($hfile,"0x0+0+0");
after the first crop. This will remove any virtual page info which may be interfering with the second crop.

Pete
Yup that fixed it.

Surely MagickCropImage should do this automatically?

Post Reply