Last updated: Apr-19-2023
You can upload animated images to Cloudinary, resize and crop them, further transform them, optimize them, convert them to modern video or animated image formats and create new animated images.
Transforming animated GIFs
Animated GIFs can be transformed like any other image uploaded to Cloudinary. For example:
- Original uploaded
- Resized to a width of 200 pixels (height is adjusted automatically to keep the aspect ratio):
- Cropped to a height and width of 200 pixels with rounded corners:
Deliver a single frame
page parameter (
pg in URLs) to deliver only a single frame of an animated GIF. For example, to deliver the second frame in the
kitten_fighting GIF file:
Control the delay between frames
delay parameter (
dl in URLs) to control the amount of time (in milliseconds) that passes between displaying the individual frames in an animated GIF. For example, to deliver the
kitten_fighting GIF with a delay of 200 milliseconds between frames:
Set a fixed looping value
By default, animated GIFs with a
image run in an infinite loop. Use the
loop effect (
e_loop in URLs) to limit the number of loops. The
loop parameter value is 0-based. For example, to set your GIF to loop only 3 times:
Converting an animated GIF to video
To deliver an animated GIF as a video file, simply change the file extension to either the
webm or the
mp4 video format. The file is automatically converted to a video format and codec that best fits web and mobile browsers. The default quality settings represent an optimized trade-off between visual quality and file size. See the article on Reduce size of animated GIFs, automatically convert to WebM and MP4
For example, to deliver the
kitten_fighting GIF as an MP4 video, reducing the file size by 95%:
The video file can also be delivered using Cloudinary's video tags and further transformed like any other video file. For more details, see Video Transformations.
Using f_auto and specifying the media type
If you want to convert the animated GIF to video and use automatic format selection, you can use the media type option (
f_auto:video) to ensure a video format is used.
For example, to deliver the
kitten_fighting GIF as a video in the most optimal format:
Convert a fetched animated GIF to video
When working with fetched remote images, you must specify the fetched image URL exactly as it is in the remote location, including file extension. Therefore, if you want to convert a fetched animated GIF to MP4, use the
f_) parameter to convert the format to MP4.
Converting an existing animated image to other animated formats
You can convert animated images to other animated image formats.
When deciding which format to use, consider the following:
- Animated GIFs are universally supported. Animated WebPs, animated AVIFs and animated PNGs are supported on most, but not all, browsers.
- Animated AVIF is based on the AV1 video codec that was released in 2019 and shares the same compression and quality levels.
- Animated PNG, WebP and AVIF support 24-bit RGB color with an 8-bit alpha channel, compared to GIF's 8-bit color and 1-bit alpha.
- AVIF and WebP support both lossy and lossless compression (a single animation can combine lossy and lossless frames), well-suited to animated images created from real-world videos. GIF and PNG only support lossless compression.
- AVIF requires fewer bytes than WebP, which itself requires fewer bytes than GIF and PNG.
- Animated GIF converted to animated AVIF can provide over 90% byte savings.
- Animated GIF converted to animated WebP can provide between 64% byte savings (lossy WebP), to 19% byte savings (for lossless WebP).
- There are different transformation counts for different animated formats.
To deliver an animated AVIF instead of an animated GIF, change the file extension to
.avif. To deliver an animated WebP or PNG instead of an animated GIF, change the file extension to
.png and set the
flag parameter to
fl_apng in URLs). For example, delivering the animated GIF called
kitten_fighting as an animated WebP:
As not all the animated formats are supported by all browsers, you can leave it up to Cloudinary to decide which format to serve to the requesting browser. Do this by setting the
fetch_format parameter to auto (or
f_auto in URLs). For example, to deliver
kitten_fighting in the best format for the requesting browser:
- Although animated PNGs are supported only in some browsers and versions, animated PNGs are backward compatible, so all browsers can show the first frame of an animated PNG, even if they don't directly support animated PNGs.
- Single-frame animated WebP is not supported. Therefore, if you supply a
.giffile that is defined as an animated GIF, but has only one frame, then
f_autowill always deliver it as a
.gifand not as an animated
.WebP, even in browsers where animated WebP is supported.
- To enable animated AVIF to be supported as a possible returned format for
f_autoin your Cloudinary product environment, contact support.
- Converting from animated WebP or animated PNG to animated AVIF is not supported. You can convert to an animated AVIF only from an animated GIF or video.
Applying lossy GIF compression
The compression algorithms used in GIFs are lossless, and there is no loss of data when compressing this palette-based format. The "lossiness" comes in when the GIF is first filtered or altered so that the image can then compress more efficiently. The loss of data occurs in this filtering phase by increasing redundant patterns along scan lines to subsequently improve the actual compression and decrease the file size.
To automatically use lossy compression when delivering your animated GIF files, set the
flag parameter to
fl_lossy in URLs). For example, the
kitten_fighting animated GIF has a file size of 6.3 MB without lossy compression, and a file size of 2.5 MB with lossy compression. The file still looks good and is now 40% of the original size:
To control the level of lossy compression in the resulting animated GIF add the
quality parameter (
q in URLs), which has a default value of 80 (applied in the example above). For example, enabling lossy compression for the
kitten_fighting GIF and also setting the quality parameter to 50 results in a file size of 2.1 MB - 33% of the original file size.
Creating animated images
There are several ways to create animated images using Cloudinary:
- Use the multi method to combine several still images into a single animated image.
- Use the zoompan effect to create an animated image by using zooming and panning techniques on the image.
- Transform a video into an animated image, as explained in Converting videos to animated images.
You can create a single animated image (GIF, PNG or WebP) or video (MP4 or WebM) from multiple image assets, where each asset is used as a single frame of the resulting animated image or video.
Animated images can be created from a maximum of 500 frames (individual images), except in the following cases where the maximum is 100 frames:
- If the processing is done in a synchronous mode (i.e., without the
asyncparameter set to true).
- If there is an underlay or overlay added to the image (
- If any transformation parameters are added that are not on the following list:
- If the
angleparameter is added with a value that is anything but
- If the
cropparameter is added with a value that is anything but
If the limit is exceeded, only the first 500 (or 100) images will be included.
Step 1: Upload all the images to be included in the animated image or video. Make sure that you include:
- An appropriate public ID when uploading each of the files; when they are merged into a single animated image or video, they are sorted alphabetically by their public IDs.
- An identical tag for all images. The tag must be unique to these images only; the animated image creation process finds all images with the same tag and merges them into a single file.
Step 2: Use the multi method of the upload API to create the animated image or video. If the images to be merged are not all the same size, you can add transformation parameters to the URL to crop them accordingly (using one of the crop modes plus
height, etc). For example, to create an animated GIF from all images with the tag
Step 3: To deliver the animated image, use the Cloudinary image delivery URL with
type set to
multi. For example, to deliver an animated GIF created from all images with the tag
The following example showcases a method to create a very simple animated GIF of revolving text consisting of 20 individual frames. A script is executed to upload the individual images to Cloudinary, where each individual image (frame) is constructed from:
- A previously uploaded blank image used as a base image.
- A text string overlaid over the base image.
Each frame is a combination of the base image together with an overlay of a slightly modified version of the text string. The text is modified for each frame with the
distort effect parameter to change its perspective.
After the script is run and the images are uploaded, the following URL delivers the animated GIF:
Use the zoompan effect to apply zooming and/or panning to an image, resulting in an animated image.
For example, you could take this image of a hotel and pool:
...and create an animated version of it that starts zoomed into the right-hand side, and slowly pans out to the left while zooming out:
Or, you can specify custom co-ordinates for the start and end positions, for example start from a position in the northwest of the USA map (x=300, y=100 pixels), and zoom into North Carolina at (x=950, y=400 pixels).
If you want to automate the
zoompan effect for any image, you can use automatic gravity (
g_auto in URLs) to zoom into or out of the area of the image which Cloudinary determines to be most interesting. In the following example, the man's face is determined to be the most interesting area of the image, so the zoom starts from there when specifying
There are many different ways to apply zooming and panning to your images. You can apply different levels of zoom, duration and frame rate and you can even choose objects to pan between. Check out the transformation reference for details.
Read this blog to see some more applications of the