How to Combine PNG Files in Python

Cloudmersive
2 min readJan 26, 2023

--

If you’re developing an application which handles a large volume of image files, adding a service to combine image files into an array will dramatically increase the efficiency of certain tasks. Thankfully, you can easily merge multiple PNG files together in just a few lines of code by calling the free-to-use API solution below.

To install the SDK, run the following command:

pip install cloudmersive-convert-api-client

Then add the imports and call the function:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint

# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'



# create an instance of the API class
api_instance = cloudmersive_convert_api_client.MergeDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file1 = '/path/to/inputfile' # file | First input file to perform the operation on.
input_file2 = '/path/to/inputfile' # file | Second input file to perform the operation on.
input_file3 = '/path/to/inputfile' # file | Third input file to perform the operation on. (optional)
input_file4 = '/path/to/inputfile' # file | Fourth input file to perform the operation on. (optional)
input_file5 = '/path/to/inputfile' # file | Fifth input file to perform the operation on. (optional)
input_file6 = '/path/to/inputfile' # file | Sixth input file to perform the operation on. (optional)
input_file7 = '/path/to/inputfile' # file | Seventh input file to perform the operation on. (optional)
input_file8 = '/path/to/inputfile' # file | Eighth input file to perform the operation on. (optional)
input_file9 = '/path/to/inputfile' # file | Ninth input file to perform the operation on. (optional)
input_file10 = '/path/to/inputfile' # file | Tenth input file to perform the operation on. (optional)

try:
# Merge Multple PNG Files Together
api_response = api_instance.merge_document_png_multi(input_file1, input_file2, input_file3=input_file3, input_file4=input_file4, input_file5=input_file5, input_file6=input_file6, input_file7=input_file7, input_file8=input_file8, input_file9=input_file9, input_file10=input_file10)
pprint(api_response)
except ApiException as e:
print("Exception when calling MergeDocumentApi->merge_document_png_multi: %s\n" % e)

To call this API for free, create a free account on our website and supply your free-tier API key in the configuration.api_key field above. With a free-tier key, you’ll get a limit of 800 API calls per month and no additional commitments (your total will reset the following month once the limit is reached).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet