Animated gif, setImagePage incorrect after crop

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
vbaspcppguy
Posts: 3
Joined: 2012-02-27T17:01:07-07:00
Authentication code: 8675308

Animated gif, setImagePage incorrect after crop

Post by vbaspcppguy »

I'm cropping animated GIFs and the result of some of them is incorrect. Everything I've found says that setting the Page should fix it but it doesn't.

Source Image:
Image

Result Image: (Note the extra transparent area)
Image

I've tried:
- setImagePage before coalesceImages
- setImagePage after deconstructImages
- using the setPage function
- Saving the image, loading it again and recropping it (does nothing)
- doing setImagePage(0, 0, 0, 0)
- doing setImagePage(null, null, null, null)

Notes:
- If I also resize the result smaller, things work fine.
- ImageMagick claims the resulting image is the right size.

Details:
Example: http://mafiareturns.com/admin/matt_stuf ... k/crop.php
Source: http://pastebin.com/J02KqTrw

ImageMagick Version: ImageMagick 6.7.5-3 2012-02-24 Q16 http://www.imagemagick.org
PHP Extension Version (Gentoo package): dev-php/pecl-imagick version 3.0.0-r1
OS: Gentoo

Edit://Oops.
vbaspcppguy
Posts: 3
Joined: 2012-02-27T17:01:07-07:00
Authentication code: 8675308

Re: Animated gif, setImagePage incorrect after crop

Post by vbaspcppguy »

I did some testing with the command line tools which I had never used before and was able to get a good image as well as duplicate the results that Imagick is creating.

This one works fine, creates the desired results:

Code: Select all

convert haters-owl.gif -coalesce -crop 100x100+25+25\!  console_test.gif
This one creates an animated gif with extra transparent area on the right and bottom sides:

Code: Select all

convert haters-owl.gif -coalesce -crop 100x100+25+25\! -layers OptimizePlus  console_test.gif
I used the same file in the example in the last post.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Animated gif, setImagePage incorrect after crop

Post by fmw42 »

this sounds similar to the problem reported at viewtopic.php?f=1&t=20227&p=80411&hilit ... ize#p80392. See the whole set of replies, esp, from Anthony. You may need to upgrade your IM version.
DJ Mike
Posts: 33
Joined: 2010-06-29T19:07:53-07:00
Authentication code: 8675308

Re: Animated gif, setImagePage incorrect after crop

Post by DJ Mike »

Try setimagepage().

Image
Dimensions 240 x 92
Size 135691 bytes
Number Of Colors 79
Format GIF
Frames 25

Working cropper
http://eclecticdjs.com/mike/wtv/tools/i ... rop_03.php

Source
http://eclecticdjs.com/mike/wtv/tools/i ... rop_03.txt

Needs these to upload and some functions:
http://eclecticdjs.com/mike/wtv/tools/i ... ctions.txt
http://eclecticdjs.com/mike/wtv/tools/i ... upload.txt

Relevent code:

Code: Select all

$image = new Imagick($_SESSION[path]);

##################
if ( $_GET[action] == "Crop" ) 
   {  
    foreach ($image as $frame)
    { $frame->cropimage( $w, $h, $ul_x, $ul_y); }
   }
##################
# Reset geometry
foreach ($image as $frame)
 { $frame->setimagepage( $w, $h, 0, 0); }
 
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
vbaspcppguy
Posts: 3
Joined: 2012-02-27T17:01:07-07:00
Authentication code: 8675308

Re: Animated gif, setImagePage incorrect after crop

Post by vbaspcppguy »

I use setImagePage, and have tried it everywhere. As I have it now, it does do what its supposed to MOST of the time.
Post Reply