Convert a GIF to PNG in JavaScript

Cloudmersive
1 min readApr 13, 2021

When performing image format conversions, you don’t want to burn your valuable production time writing the complex code needed for the process. For example. If you have a GIF you need to transformed into a PNG, instead of building the operation out manually, we will demonstrate how you can use an API to automatically run the conversion in seconds.

We will begin the operation by installing the jQuery library:

bower install jquery

Then, we can call the conversion function with the following code:

var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");
var settings = {
"url": "https://api.cloudmersive.com/image/convert/to/png",
"method": "POST",
"timeout": 0,
"headers": {
"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);
});

The output will be your new PNG file! If you need to retrieve your API key, head over to the Cloudmersive website to register for a free account; this will give you access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive

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