How to Convert a Video to GIF in JavaScript

Cloudmersive
1 min readJun 25, 2021

--

The Graphic Interchange Format, or GIF, has become an increasingly popular as an engaging and entertaining way to communicate and advertise. Using GIFs to reach your customer base via email, social media, or otherwise can be a great way to deliver content without losing the interest of your audience. The following API can be used in JavaScript to convert a video from its current format to GIF, providing a simple way to deliver your message.

Now, let’s kick things off by installing the jQuery library:

bower install jquery

Then, we can call the function with the below code:

var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/video/convert/to/gif",
"method": "POST",
"timeout": 0,
"headers": {
"fileUrl": "<string>",
"maxWidth": "<integer>",
"maxHeight": "<integer>",
"preserveAspectRatio": "<boolean>",
"frameRate": "<integer>",
"startTime": "<dateTime>",
"timeSpan": "<dateTime>",
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

Your new GIF can now be shared via whatever medium you choose! If you need to obtain an API key, head over to the Cloudmersive website to register for a free account; this provides 800 calls/month across our multitude of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet