A user reports that embedded GIFs in Discourse posts freeze on the first frame, despite working in previews and external tabs. Various workarounds, including using external links and raw HTML, fail. Another user reproduces the issue in Chrome and suggests using gifscicle to optimize the GIFs, which resolves the problem. The issue is traced to malformed GIFs, particularly those generated by ScreenToGif’s Neural Network feature. The solution involves optimizing GIFs with gifscicle, sometimes requiring the --colors 256 flag. Additionally, the discussion notes that the GIF thumbnail not animating is due to a bug in FastImage, which has been fixed and is now available in the latest version. Plunkett_Barry and Falco are key contributors, with nbianca providing updates on the bug fix. zogstrip also contributes to the discussion on the thumbnail issue.
I’m running into a problem embedding custom gifs (created with ScreenToGif) in Discourse posts. When I embed a gif, it works a moment then freezes on the first frame, e.g.:
It appears to work as expected in the post preview. And when I open the uploaded gif in a new tab, it works there too. It only freezes on Discourse itself.
I’ve tried four workarounds:
uploading the gif to another website (e.g. an S3 bucket), then linking to it. That works until the system bot comes along and downloads it locally, at which point it freezes again.
I also thought this might have something to do with resizing, so I tried removing the markdown formatting for the image, e.g.:
Since the gif worked when I followed the link to a new tab, I tried replacing the shorthand “upload” URI with the full URL of the uploaded image, e.g.:
Finally, I thought the problem might have something to do with Discourse’s interpretation of the markdown code, so I tried using a raw html image tag with the full URL of the uploaded image:
Since it’s working here, but not on your site I suggest doing a rebuild of your site and trying again. We did lots of recent changes around gifs. For some periods we had bugs like your report and your site may be in an affected version.
Definitely not a file size, but a “malformed” file that gifscicle is fixing. It’s common to see some tools making bad files. I always pass my GIFs to a good tool like ffmpeg before sharing. But even then you can get easily a malformed file if dimensions are odd, for example.
GIF is a complicated format, and there are better options nowadays like MP4 and WEBP for most applications.
For what it’s worth, I’ve found a couple cases where gifsicle doesn’t work. Specifically, sometimes using --colors 256 is required to get a working gif. But other times, leaving the flag out is necessary.