How to Composite Two Images Together using Python

pip install cloudmersive-image-api-client
from __future__ import print_function
import time
import cloudmersive_image_api_client
from cloudmersive_image_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_image_api_client.EditApi(cloudmersive_image_api_client.ApiClient(configuration))
location = 'location_example' # str | Location to composite the layered images; possible values are: \"center\", \"top-left\", \"top-center\", \"top-right\", \"center-left\", \"center-right\", \"bottom-left\", \"bottom-center\", \"bottom-right\"
base_image = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
layered_image = '/path/to/inputfile' # file | Image to layer on top of the base image.
try:
# Composite two images together
api_response = api_instance.edit_composite_basic(location, base_image, layered_image)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditApi->edit_composite_basic: %s\n" % e)
# create an instance of the API class
api_instance = cloudmersive_image_api_client.EditApi(cloudmersive_image_api_client.ApiClient(configuration))
base_image = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
layered_image = '/path/to/inputfile' # file | Image to layer on top of the base image.
top = 56 # int | Optional; Desired distance in pixels from the top of the base image to the top of the layered image. (optional)
bottom = 56 # int | Optional; Desired distance in pixels from the bottom of the base image to the bottom of the layered image. (optional)
left = 56 # int | Optional; Desired distance in pixels from the left side of the base image to the left side of the layered image. (optional)
right = 56 # int | Optional; Desired distance in pixels from the right side of the base image to the right side of the layered image. (optional)
width = 56 # int | Optional; Desired width of the layered image in pixels. Leave height empty or 0 to automatically scale the image proportionally. (optional)
height = 56 # int | Optional; Desired height of the layered image in pixels. Leave width empty or 0 to automatically scale the image proportionally. (optional)
try:
# Composite two images together precisely
api_response = api_instance.edit_composite_precise(base_image, layered_image, top=top, bottom=bottom, left=left, right=right, width=width, height=height)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditApi->edit_composite_precise: %s\n" % e)

--

--

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
Cloudmersive

Cloudmersive

437 Followers

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