How to get image information in Node.JS

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?

Image for post
Image for post

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