Page 1 of 1

Re: Cropping a Resized GIF

Posted: 2007-10-03T14:02:52-07:00
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. :)

Re: Cropping a Resized GIF

Posted: 2007-10-03T14:58:05-07:00
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

Re: Cropping a Resized GIF

Posted: 2007-12-12T17:10:04-07:00
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).

Re: Cropping a Resized GIF

Posted: 2007-12-12T18:59:39-07:00
by el_supremo
Thanks Anthony. I've added that info to my IM notes.

Pete

Re: Cropping a Resized GIF

Posted: 2007-12-12T21:54:40-07:00
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.