How to Resize an Image with JavaScript

Cloudmersive
1 min readMay 25, 2022

Looking for a way to manipulate photos automatically? Thankfully, there’s a Cloudmersive API for that. Our Image Resizing API is exif-aware and provides customizable width & height parameters for the output image. To structure your API call in JavaScript, take advantage of the code provide below in this article, or visit our API page for code examples in a dozen other common programming languages.

Let’s first begin installation of the jQuery library by running the below command:

bower install jquery

Next, let’s include a snippet to capture the input image file(s):

var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");

Finally, call the API:

var settings = {
"url": "https://api.cloudmersive.com/image/resize/target/<integer>/<integer>",
"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);
});

All done. To get a Cloudmersive API key, head to our website and register for a free account.

--

--

Cloudmersive

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