Perl API: animated GIF thumbnailing/optimization issues
Posted: 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.
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.