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.
Perl API: animated GIF thumbnailing/optimization issues
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Perl API: animated GIF thumbnailing/optimization issues
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.
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
Re: Perl API: animated GIF thumbnailing/optimization issues
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.
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Perl API: animated GIF thumbnailing/optimization issues
Okay, so it sounds like a problem with Perl. Sorry, I can't help with that.
snibgo's IM pages: im.snibgo.com