Comments

diwant’s picture

Yes! It worked

diwant’s picture

Assigned: diwant » Unassigned
Status: Active » Needs review

Whoops, changed the state.

sun’s picture

According to #1115658-1: Animated GIF image gets broken on resize with ImageMagick toolkit, the -coalesce option breaks animated GIFs. :-/

+++ b/imagemagick.module
@@ -201,7 +201,11 @@ function _imagemagick_check_path($file) {
+  if($image->info['mime_type'] == 'image/gif') {
+    $extra = '-coalesce ';
+  }

Instead of $extra, why not add a new ops[] before the existing -resize?

alexku’s picture

Attached a patch which uses $image->ops[] instead of extra.

Tested with imagemagick (convert). Doesn't work when graphicsmagick (gm).

attiks’s picture

Status: Needs review » Reviewed & tested by the community

#4 Works for me, tx

andros’s picture

Wonder why this it not allready part of the dev version? Is there a blocker?

nickgs’s picture

#4 worked well for me too. Thanks.

F117’s picture

Issue summary: View changes

#4 confirmed working. :)

elliotttf’s picture

Another +1 for me. I had an issue with another patch from the ImageMagick Advanced module, but was able to address that over there: #1883192-11: Option for progressive jpeg.

q11q11’s picture

Correct version of #4

kristofferwiklund’s picture

Patch in #10 works great. Thanks.

elijah lynn’s picture

Issue summary: View changes
klase’s picture

Also confirming that patch in #10 works great. Look forward to seeing this in next release!?

elijah lynn’s picture

Another confirmation here.

elijah lynn’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/imagemagick.module
@@ -201,6 +201,9 @@ function _imagemagick_check_path($file) {
+  if($image->info['mime_type'] == 'image/gif') {

Needs a space between if and first '('.

tobiberlin’s picture

Confirming that it works

q11q11’s picture

Fixed #10 according to coding standards.

elijah lynn’s picture

Status: Needs work » Reviewed & tested by the community

Thanks q11q11

mbrc’s picture

+1, #17 works for me as well.

ñull’s picture

#17 works for me as well. Please commit to a release version.

scotwith1t’s picture

StatusFileSize
new8.54 MB
new876 KB

This seems to fix the rendering problem, but if I have a large gif like this
large, long animation

it shortens the animation sequence when it's resized? (Notice how it restarts the animation shortly after the graph overlay shows up, whereas the top full gif shows the full sequence all the way to flipping over the graph)
resized

Is this a function of the file size being shrunk or something?

scotwith1t’s picture

Any update on this? Hate to patch this module on yet another project for this problem...looks like you guys have been working hard to get a D8 version, so I totally understand, but if we could get this committed and a new release with it in there, I'd be grateful. If we can address my last comment as well, even better!

mondrake’s picture

@scotself actually it seems there's no one attending at the D7 version of this module lately. I have ported to D8 and am maintaining that version but have no intention to maintain the D7 one - see #2558165: Offering to maintain a 8.x-1.x branch of ImageMagick for details. If anyone is interested to apply for maintainership of the D7 version, details are in the same issue.

howdytom’s picture

#17 works great! Thank you. Scaling GIF animation is working again. Note. If your GIF result still looks weird, make sure to hit „update style“ button in example.com/config/media/image-styles/edit/yourstyles

@mondrake: Please commit the patch to Drupal 7 release.

nico.knaepen’s picture

When is this change going to be commited?

pedrosp’s picture

In my case patch #17 was not enough, because I wanted to scale, crop or smart crop an animated GIF.
The patch only enhance the resize function with "-coalesce", but as pointed in this stackoverflow answer, we need also to override the crop function.
I have updated the function with this following code and it did the trick for me:

function image_imagemagick_crop(stdClass $image, $x, $y, $width, $height) {
  // Even though the crop effect in Drupal core does not allow for negative
  // offsets, ImageMagick supports them. Also note: if $x and $y are set to
  // NULL then crop will create tiled images so we convert these to ints.
  if ($image->info['mime_type'] == 'image/gif') {
    $image->ops[] = '-coalesce';
    $image->ops[] = '-repage 0x0';
  }
  $image->ops[] = sprintf('-crop %dx%d%+d%+d!', $width, $height, $x, $y);
  $image->info['width'] = $width;
  $image->info['height'] = $height;
  if ($image->info['mime_type'] == 'image/gif') {
    $image->ops[] = '+repage';
  }
  return TRUE;
}
Chris Charlton’s picture

+1

karlshea’s picture

Reroll with changes from #26, additionally applying the same changes to image_imagemagick_resize()

rgpublic’s picture

I've attached patch #28 ported to D8 just in case anyone finds this useful.

jcmartinez’s picture

I can confirm that #29 worked for me on Drupal 8.
Note that it only works with ImageMagick, but it doesn't work with GraphicsMagick.

asrob’s picture

Updated patch to work with 8.x-2.x-dev.

leovw’s picture

Version: 7.x-1.x-dev » 8.x-2.3

I can confirm that #31 is working for me, thank you for this! Surely this should be added to the Imagemagick module?

mondrake’s picture

Version: 8.x-2.3 » 7.x-1.x-dev

Sorry, not in the 8.x version. Please see #2949193: ImageMagick scale breaks animated gifs (D8) and #2786435: Support '-coalesce' of Animated GIF image files for alternatives.

Moving back to 7.x branch for @Chris Carlton to make a call.

In general - my understanding is that 'coalesce' will boost the size of multiframe images because it resizes all frames to the largest dimensions, losing any optimization that could have been stored in the original image. So if we had this in, someone will be happy for the fit-to-purpose, and someone will be unhappy for the image sizes. At least, one should decide which way to go and in D8 there are alternatives ways to get there without forcing everybody to do the same.

rgpublic’s picture

Hm, I'm not quite sure if you aren't artificially over-complicating things, @mondrake. Yes, coalesce will lose any optimization coming from shrink-to-fit frame sizes, but losing this kind of optimization usually doesn't blow up filesize unreasonably due to GIF's run length encoding. Further ImageMagick processing might even involve other steps than just scaling, so I think it makes sense to re-optimize the final image anyway if you are really trying to achieve top-notch results. You could do this e.g. with the imageapi_optimize module etc. Currently, though, the image is destroyed, so I think in terms of out-of-the-box experience, it should be fixed with this simple fix without losing too much flexibility.

Chris Charlton’s picture

Assigned: Unassigned » Chris Charlton

I'll review for 7.x with a couple of GIFs and report back.

firewaller’s picture

+1

Chris Charlton’s picture

I remember this working for D7. I'll need to double-check.

auth’s picture

Imagemagick 3.x has removed some functions from ImagemagickToolkit. This is the patch in #31 using arguments() to get and modify arguments.

rgpublic’s picture

Imagemagick *3.x* ? Are you sure? The current version is 7.x! 3.x doesn't exist for decades, I suppose:

https://imagemagick.org/index.php

rgpublic’s picture

Ah, you mean the Drupal module "imagemagick". Sorry for the spam. Understand now.

auth’s picture

Understandable misunderstanding, I could have been more descriptive in my comment.

Here is a retry of a functional patch.

Slimbips’s picture

is it possible someone applys the patch and uploads it?, i have hard times figuring out how to patch, or nothing happens at all or patch fails all the time

howdytom’s picture

patch -p1 < imagemagick-resize_animated_gifs-1802534-41.patch

Slimbips’s picture

Cool thanks, i guess the patch worked---> https://ibb.co/zHgKDxj
But the animation isnt fixed on my website :(

EDIT: nvm the avatar wasnt going through imagemagick resize, changed in the view to resize and problem solved, thanks!

tostinni’s picture

@Slimbips it may due to the images being already generated in your sites/default/files/styles folder.
The radical thing to do to force mass rebuild is to delete this folder (which only contains images generated by images styles, the original are located in sites/default/files/2021-03... folders).

If you have a specific image style that causes problem, you can delete its folder sites/default/files/styles/IMAGE_STYLE_MACHINE_NAME

Don't forget to do a backup of it ;).

auth’s picture

Attached is an updated patch that work with the latest version

ipo4ka704’s picture

Version: 7.x-1.x-dev » 8.x-3.x-dev

I think needs to move it to new version.

mondrake’s picture

Version: 8.x-3.x-dev » 7.x-1.x-dev

No, it’s fixed in D8 and later, see child issue.

mondrake’s picture

Status: Reviewed & tested by the community » Closed (outdated)

Drupal 7 is EOL