Perl API: animated GIF thumbnailing/optimization issues

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
bit0mike
Posts: 2
Joined: 2016-03-09T17:39:44-07:00
Authentication code: 1151

Perl API: animated GIF thumbnailing/optimization issues

Post by bit0mike » 2016-03-10T09:50:25-07:00

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. :)

snibgo
Posts: 9399
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Perl API: animated GIF thumbnailing/optimization issues

Post by snibgo » 2016-03-10T10:07:07-07:00

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.
snibgo's IM pages: im.snibgo.com

bit0mike
Posts: 2
Joined: 2016-03-09T17:39:44-07:00
Authentication code: 1151

Re: Perl API: animated GIF thumbnailing/optimization issues

Post by bit0mike » 2016-03-10T10:11:52-07:00

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.

snibgo
Posts: 9399
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Perl API: animated GIF thumbnailing/optimization issues

Post by snibgo » 2016-03-10T10:29:01-07:00

Okay, so it sounds like a problem with Perl. Sorry, I can't help with that.
snibgo's IM pages: im.snibgo.com

Post Reply