How to change the DPI of a photo in Javascript

Cloudmersive
2 min readMar 11, 2020

--

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="https://cdn.cloudmersive.com/jsclient/cloudmersive-document-convert-client.js"></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!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet