How to get image information in Node.JS

Cloudmersive
1 min readApr 1, 2020

--

Today’s quick tutorial will explain how to acquire a range of details from an image file including compression, DPI, format, etc. We can perform this task very easily by using an API that’s already set up for the job.

Let’s start with installation, accomplish through npm install.

npm install cloudmersive-convert-api-client --save

Moving right along, we can call our image information function from the API using this snippet:

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 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.convertImageGetImageInfo(inputFile, callback);

Now enter your image to get its information, including format, size, MIME type, EXIF data, DPI, transparency, unique colors, compression, and more. Wasn’t that easy?

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet