Page 1 of 1

Perl API: animated GIF thumbnailing/optimization issues

Posted: 2016-03-10T09:50:25-07:00
by bit0mike
Having some trouble resizing animated GIFs using the Perl Image::Magick module.

ImageMagick 6.9.3-4 built from FreeBSD ports. (They don't have 6.9.3-7 just yet.)

my $imgobj = Image::Magick->new;
$imgobj->Read(blob => $some_animated_gif_data);
$imgobj = $imgobj->Coalesce();
my $newimgobj = $imgobj->Clone;
$newimgobj->Thumbnail( 'width' => $new_x, 'height' => $new_y );
$newimgobj->Layers( 'method' => 'optimize' );
$newimgobj->Strip;

While this *works*, the layer optimize step doesn't actually do anything, so often the thumbnails are significantly larger than the original images (because they contain full coalesced frames instead of optimized partial frames). If I instead try:

$newimgobj = $newimgobj->Layers('method' => 'optimize');

...I only get the first frame of the animation. (I've also tried assigning to an array, but the array only has one element; an object with one frame -- so, same problem.)

I have to be missing something reeeeeeally, really stupidly obvious here. :)

Re: Perl API: animated GIF thumbnailing/optimization issues

Posted: 2016-03-10T10:07:07-07:00
by snibgo
So, your problem is that the optimize step doesn't reduce file size?

If so, I suggest you ty it at the command line. If that also doesn't reduce the filesize, then it's not a problem with the Perl.

Resizing introduces new colours, even when down-sizing. If that is the problem, try using "-scale". I don't know how to do that in Perl.

Re: Perl API: animated GIF thumbnailing/optimization issues

Posted: 2016-03-10T10:11:52-07:00
by bit0mike
Basically, I'm trying to emulate this (apparently working) command line in Perl:

convert imresizetest.gif -coalesce -thumbnail 223x132 -layers Optimize imresizetest-thumb.gif

And yes, that command line does drop the file size, as you can see if you feed it http://www.bit0.com/tmp/imresizetest.gif as a sample input. In Perl the output is larger and all the frames are the same size (per 'identify' at the command line) vs varying sizes from the command-line version.

Re: Perl API: animated GIF thumbnailing/optimization issues

Posted: 2016-03-10T10:29:01-07:00
by snibgo
Okay, so it sounds like a problem with Perl. Sorry, I can't help with that.