Action text merrily accepts a gif upload through the trix editor.
However when it is actually displayed - it seems to show a variant which has been ‘flattened’ to show only the first frame of the gif.
Is there a way to either show the original gif, or to tweak things so that the variants are not flattened?
First of all, ActiveStorage hardcodes the image’s first frame when doing a transformation, which breaks animated GIFs. You can solve this by setting the page to nil alongside your other transformations. If you are resizing the GIF, for example:
This solves the animation problem, but you’ll still run into weird layering issues if you’re working with optimized GIFs. You’ll need to remove these optimizations before calling resize (or resize_to_limit) when creating the variant. Putting everything together:
thanks for your response. I can see how this would help if I was taking a gif and transforming it myself - however in this case, the gif is an attachment in ActionText.
the full code isn’t much more than
has_rich_text :description
in my model and a form field to accept it.
Can I ‘tell’ ActionText how it should handle gif attachments?
ActionText is deeply integrated with ActiveStorage. When you attach something to your editor, you’re using AS behind the scenes, including how it renders attachments by default.
You should have a partial in app/views/active_storage/blobs/_blob.html.erb that calls blob.representation(...)—this is where it applies the transformations for the attachment.