Providing automatic file thumbnails are an excellent way to improve usability of your project. Creating these thumbnails from big clunky PPTX files, however, can certainly prove problematic if you don’t have the correct approach. Attempt to manually set up this feature and you will be in for a painful, multi-step problem with tons of possibilities for bugs and regression problems in your project. But, with the help of an API, we can offload the problem to the cloud and still get the quality results that we are looking for.
Start with pip installation; our client requires this command:
pip install cloudmersive-convert-api-client
Now call the thumbnail function. No need to enter the file format, as that will automatically be detected, allow a high degree of flexibility in how this function is used.
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)
And just like that, we’re finished. So much time saved.