Today, I will be showing you Python users out there a super simple way of converting EML files into customizable thumbnails. Forget all those potential pitfalls that can easily arise from the many-stepped process that would normally be required. All that can be done for us by a thumbnail API, which I will demonstrate for you now.
Let’s install that client as our first step now.
pip install cloudmersive-convert-api-client
Moving right along, our next step is a simple function call for the thumbnail function from that client. Note that it automatically detects the incoming format, and works with many other formats besides EML.
from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.ConvertDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.max_width = 56 # int | 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. (optional)max_height = 56 # int | 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. (optional)extension = 'extension_example' # str | 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. (optional)try:# Convert File to Thumbnail Imageapi_response = api_instance.convert_document_autodetect_to_thumbnail(input_file, max_width=max_width, max_height=max_height, extension=extension)pprint(api_response)except ApiException as e:print("Exception when calling ConvertDocumentApi->convert_document_autodetect_to_thumbnail: %s\n" % e)