Archived from the Transloadit support forum. Originally posted on January 16, 2012; details may be outdated, see our docs for current behavior. Original thread
I’ve noticed that the majority of animated gifs upload don’t maintain their animation. Did you guys change something about how you handle animated gifs?
We don’t use frame:1 for the large image size, just for the thumbnails.
Does strip:true for the large image size strip out the other frames of the animated gif? Can’t remember, but we may have added that to the template recently, so that could be the problem.
I debugged this. The problem is the flatten parameter, which has a default value of true, which solves quite a few issues. This does not work for gif files though, as it loses the animation.
I think the best way to solve this would be to have a default value of “auto” which flattens all non-gif conversions, but not gif-conversions. What do you think?
Alternatively we could just keep it as it is and do not flatten gif files, even though the flatten parameter is set to “true”. To deal with animated gif files, people could still make use of the “frame” parameter.
I’m not really familiar with the flatten param, as I don’t deal with transparent images, but the first suggestion seems reasonable to me.
I also wanted to ask if this would be possible.. Are there any template rules that would enable me to produce a non-animated gif if the file size is above 1mb, and instead watermark another image over it (a play button icon)? If the file size is below 1mb it would create an animated gif.
I remember reading at some point (but cant find it now) a way to reference image meta-data, such as filesize, in the template to change it’s behavior on the fly.
Regarding the flatten parameter, I think I will keep it as it is and just not flatten gif files for now, as you cannot specify which frame to use with the flatten parameter anyway.
For gif files, you’d use the frame parameter. I think the expected behavior is to preserve animations by default.
I also wanted to ask if this would be possible.. If the animated gif file size
is above 1mb I’d like to produce an animated gif as well as a non-animated gif that contains a watermark of another image (a play button icon)? If the file size is below 1mb it would just create the one animated gif.
I remember reading at some point (but cant find it now) a way to reference image meta-data, such as filesize, in the template to change it’s behavior on the fly.
Would that be possible? Or would the best way to do this be to do a second call to your api after my callback is url hit by your server, and create the non-animated gif then using a different template?
you could again use the /file/filter robot for it.
Since you create the animated gif file in both cases, we can trim the problem down to just creating a watermarked version for files > 1mb.
Here is some pseudo template:
: /file/filter, proper condition, use original wm_version: use gif_gt_1mb, /image/resize robot, watermark parameters
The gist here is, that gif_gt_1mb file could pass zero files on to the wm_version step (in case the original file was below 1mb), hence the wm_version step would do nothing.