Cropping a Resized GIF

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
wortell

Re: Cropping a Resized GIF

Post by wortell »

Shawazi wrote:

Code: Select all

$size = GetImageSize('action_usage.gif'); //size of source
$dest = getHorizontalProp($size, 200);  //returns array of new dimensions
$dest_x = $dest['x'];
$dest_y = $dest['y'];

echo $dest_x.'x'.$dest_y.'<br />';
$transSize = MagickTransformImage( $original, '0x0', $dest_x.'x'.$dest_y ); //resize image

MagickCropImage( $transSize, 100, 100, 0, 0 ); //crop image

MagickWriteImage($transSize, 'action_test.gif');  //save resized image

echo '<img src="action_test.gif" alt="test" title="test" style="border: solid 1px #FF0000;" />'
I narrowed my code. It basically should resize my original image of 338x204 to
200x121.

It resizes the image itself but keeps the canvas of the image at 338x204. So with the border I'll see a 200x121 image within a lot of extra white space. It does not happen with PNGs or JPGs

I'm hopgin this gets answered soon as I'm having the same issue. :)
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Cropping a Resized GIF

Post by el_supremo »

Add this after the crop.

Code: Select all

MagickSetImagePage($transSize, 100, 100, 0, 0);
It resets the virtual canvas.
PNG and JPG do not have a virtual canvas so they don't need this.

Pete
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cropping a Resized GIF

Post by anthony »

Sorry el_supremo but PNG does save virtual canvas offset, but most browsers ignore it.
Also IM saves virtual canvas size info in PNG image meta-data, but only IM uses that information for later image processing handling. Normally Virtual Canvas info is only useful for animated images (GIF).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Cropping a Resized GIF

Post by el_supremo »

Thanks Anthony. I've added that info to my IM notes.

Pete
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cropping a Resized GIF

Post by anthony »

Sorry small change to the above....

Normally the Virtual Canvas Size, is not important except for 'flattening', or Animations.

On the other hand Virtual canvas offsets are usually only important for animations, and for intermediate processing of layered images, such multi-layer compositions, or photos being distorted for generating larger panoramic images.

PNG saves offsets normally as part of its ability to become a MNG animation. The IM saving of canvas size meta-data is specific only to IM and not supported outside of IM.

If a PNG is read in that does not have a IM canvas size meta-data info, but has a PNG offset, IM generates an appropriate canavs size so that -flatten will not clip the image expectantly. (see http://imagemagick.org/Usage/formats/#png_offsets). If no offset is present the canvas size and image size will be the same and is normal for most images without Virtual Canvas information.

I hope that makes it clear.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply