Posted by jagermonster on April 4, 2011 at 2:43pm
5 followers
Jump to:
| Project: | ImageAPI |
| Version: | 6.x-1.6 |
| Component: | ImageAPI Imagick |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
| Issue tags: | animated gif, imagemagick, resize |
Issue Summary
when an animated gif image is resized sometimes it breaks the gif. Its still animated but messes up the images in the sequence.
In imageapi_imagemagick.module line 115
function imageapi_imagemagick_image_resize(&$image, $width, $height)
Was
$image->ops[] = '-resize '. (int) $width .'x'. (int) $height .'!';
changed it to
if($image->info['mime_type'] == 'image/gif'){
$image->ops[] = '-coalesce -resize '. (int) $width .'x'. (int) $height .'!';
}else{
$image->ops[] = '-resize '. (int) $width .'x'. (int) $height .'!';
}
Adding the -coalesce function, now the animated gif image resize correctly
Comments
#1
I just ran into this issue and the ImageMagick "-coalesce" switch is indeed required for correctly resizing animated gifs without messing them up. The above fix corrects the issue.
However, the ImageMagick documentation says:
Does that mean it shouldn't really be applied to all gif files? Is there any way to specifically detect animated gifs in the PHP logic or something?
#2
Subscribing.
#3
@jagermonster
Thanks, this worked for me. The animations are now showing correctly.
I hacked the resize function as follows.
<?phpfunction imageapi_imagemagick_image_resize(&$image, $width, $height) {
$extra = '';
if($image->info['mime_type'] == 'image/gif') {
$extra = '-coalesce ';
}
$image->ops[] = $extra . '-resize '. (int) $width .'x'. (int) $height .'!';
$image->info['width'] = $width;
$image->info['height'] = $height;
return TRUE;
}
?>
If I had the time I would consider creating a gif safe imagecache resize action.
#4
Corresponding ImageMagick issue: #1802534: ImageMagick scale breaks animated gifs