How to change the DPI of a photo in PHP
1 min readAug 1, 2019
Today we will be looking at a simplified method to adjust photo resolution using our Convert API. The first thing to do is add a reference to the client in our library, like so:
"require": {
"cloudmersive/cloudmersive_document_convert_api_client": "^1.4",
}
And then it’s as simple as calling the convertImageImageSetDPI function and setting the desired DPI with the following code:
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);
This will return our resized photo, and we are good to go. Feel free to explore the rest of what our Convert API can do, with its robust functionality encompassing documents, HTML, and more.