Animated images

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.

Tip
You can also deliver video files as animated AVIF, GIF, PNG and WebP. For details, see Converting videos to animated images.

Transforming animated GIFs

Animated GIFs can be transformed like any other image uploaded to Cloudinary. For example:

  • Original uploaded kitten_fighting animated GIF:

Originally uploaded kitten_fighting animated GIF
  • Resized to a width of 200 pixels (height is adjusted automatically to keep the aspect ratio):

Animated GIF resized to a width of 200 pixels
  • Cropped to a height and width of 200 pixels with rounded corners:

Animated GIF cropped to 200x200 circle

Deliver a single frame

Use the 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:

2nd frame only in kitten_fighting GIF

Control the delay between frames

Use the 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:

kitten_fighting with 200 ms delay between frames

Set a fixed looping value

By default, animated GIFs with a resource_type of 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:

loop animated GIF 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 fetch_format (f_) parameter to convert the format to MP4.

For example:

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 .webp or .png and set the flag parameter to awebp or apng (fl_awebp or fl_apng in URLs). For example, delivering the animated GIF called kitten_fighting as an animated WebP:

kitten_fighting GIF delivered in webp format

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:

kitten_fighting GIF delivered in the best format for the requesting browser

Notes
  • 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 .gif file that is defined as an animated GIF, but has only one frame, then f_auto will always deliver it as a .gif and 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_auto in 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 lossy (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:

kitten_fighting with lossy compression

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.

kitten_fighting with quality set to 50

Creating animated images

There are several ways to create animated images using Cloudinary:

Multi method

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 async parameter set to true).
  • If there is an underlay or overlay added to the image (l_ or u_).
  • If any transformation parameters are added that are not on the following list: background, flags, crop, width, height, x, y, gravity, quality, angle, page, and dpr.
  • If the angle parameter is added with a value that is anything but exif or auto.
  • If the crop parameter is added with a value that is anything but scale, limit, fit, fill, thumb or crop.

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 width or height, etc). For example, to create an animated GIF from all images with the tag arrow_animation:

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 arrow_animation:

arrow_animation.gif created from all images with the arrow_animation 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:

animated_logo.gif created from all images with the spinning_text tag

Zoompan effect

Use the zoompan effect to apply zooming and/or panning to an image, resulting in an animated image.

Note
You need to transform the original image to an animated image type by either changing the extension or using the format parameter.

For example, you could take this image of a hotel and pool:

Hotel and swimming 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:

Hotel and swimming pool with zoompan effect

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).

Map of the USA with zoompan effect

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 from_(g_auto;zoom_3.4):

Man playing guitar with zoompan effect

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.

Learn more

✔️ Feedback sent!

Rate this page: