How to change the DPI of a photo in Javascript

Today’s post is not going to get into all the reasons you might change the DPI of a photo, you already know them. Instead, we are going to dive into a rapid-fire approach to achieving this in Javascript. Let’s begin.

The process starts easily enough: importing our client. Drop this script tag into your HTML file to get this done.

<script src=""></script>

Now simply call convertImageImageSetDPI, laid out below:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertImageApi();var dpi = 56; // Number | New DPI in pixels-per-inch, for example 300 DPI or 600 DPIvar inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertImageImageSetDPI(dpi, inputFile, callback);

Specify your DPI and you are all set. Now get out there and enjoy all that time you just saved!

Image for post

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store