How to change the DPI of a photo in PHP

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) {
} 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.

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