How to change the DPI of a photo in Node.js
1 min readMay 18, 2019
The first thing we need to do is add a reference to the project in the npm packages file:
"dependencies": {
"cloudmersive-convert-api-client": "^1.2.7"
}
Then we need to require the file:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
Last but not least, all we need to do is call convertImageImageSetDPI to set the DPI of the photo:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';var apiInstance = new CloudmersiveConvertApiClient.ConvertImageApi();var dpi = 56; // Number | New DPI in pixels-per-inch, for example 300 DPI or 600 DPIvar inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // 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);
From here, the DPI of the photo will be changed. We can pass in various possible values, such as 300 DPI or 600 DPI. The rescaled photo will be returned to us.
That’s all there is to it!