How to Convert a Video to GIF using an API?

A common reason for creating a GIF from a video is to capture a short fragment for use as a thumbnail or preview. Here is how to convert a specific portion of a video clip into a GIF using a single API request:

API Request
curl -s -X POST \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-binary @- << EOF
  "source": {
    "output_format": "gif",
    "gif_quality": "best",
    "gif_compression": 100,
    "frame_rate": "10 fps",
    "duration": 3,
    "elements": [
        "type": "video",
        "source": ""
Output GIF

How it works: This example uses cURL to make a request to the Creatomate API. This REST API works by using JSON to specify a video composition, which is then processed in the cloud and returned as a URL. Besides creating GIFs, it can also create videos and images.

In order to create a GIF, make sure "output_format" is set to "gif". If you want to output a different file type, there are several other formats to choose from, including "jpg", "png", and "mp4". When generating a GIF, you can modify the "gif_quality" and "gif_compression" options. Depending on whether you care more about quality or speed, you can choose "best" or "fast" from the "gif_quality" option. The "gif_compression" parameter can range from 0 to 200 and compresses a GIF's file size further, but with additional quality loss.

Additionally, the "frame_rate" is set to "10" frames per second and the GIF "duration" is set to "3" seconds. If you want to crop the GIF to a specific resolution, you can specify the "width" and "height" properties.

It is also possible to place a logo or caption on top of your GIF. Below are examples of how you can do this. Don't forget to check out the video editor too, which allows you to design your own GIF overlays and export them as JSON for easy integration into your workflows.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your application to create any kind of video – completely through code.

Related API Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free