How to convert an EML file into a Thumbnail PNG Image in Node.JS

Cloudmersive
2 min readMay 30, 2020

--

Creating thumbnail images for different file types can be quite the undertaking. EML files, for example, need to be parsed into HTML, rendered, converted to PNG, and finally resized. I probably don’t need to tell you that this is difficult to set up. What I am going to tell you is that there is a much easier way to still get your thumbnails. Let’s look at that process now.

We start with installation of the API client that we will be using by adding this reference to package.json.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

Now call the following function:

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.ConvertDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var opts = {'maxWidth': 56, // Number | Optional; Maximum width of the output thumbnail - final image will be as large as possible while less than or equal to this width. Default is 128.'maxHeight': 56, // Number | Optional; Maximum height of the output thumbnail - final image will be as large as possible while less than or equal to this width. Default is 128.'extension': "extension_example" // String | Optional; Specify the file extension of the inputFile. This will improve the response time in most cases. Also allows unsupported files without extensions to still return a corresponding generic icon.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDocumentAutodetectToThumbnail(inputFile, opts, callback);

And voila! Your thumbnails. Simple.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet