Rails Active Storage display .gif file

Post by Lưu Đại at 20-08-2023
Today when I read some article in blog, I found that gif file only display the first frame. 
I googled it and realize that by default Rails Active Storage only shows the first frame for gif file [1]
If I want to fix it we have to go to app/views/active_storage/blobs/_blob.html.erb to fix page = nil (it means rails need to remove loader page -> get all the image frames). [2]
image.png
If we resize the image as well we need option coalesce = true to display gif correctly. 
Now gif is display correctly. 

So what is loader and coalesce?

loader After I send this option to Rails Active Record representation function, this function will call loader function of image_processing then it'll call to minimagik. [3]
Loader function is used to set file type for your file. For example, how many page does it load, what is the file format (png, pdf, ..., file size (height X width))
coalesce this option will be passed to convert function of image_processing. 
coalesce function is used to resize page (frame) of gif so it'll fit the width and height (that the reason why we only need it when resize). [4]

References