How to Add a Customizable Drop Shadow to an Image using Python
When you want to add a little more depth and detail to a 2-dimensional image, drop shadows are a great choice — they’re used commonly in professional images (in logos, for example) and amateur images alike. Our Drop Shadow API allows you to generate customizable drop shadows for an input image based on specific parameters including vertical & horizontal offset, sigma (blur distance), and opacity. With this API, you can add an exciting new feature to your website’s image processing operations and personalize your images that much more.
In the below demonstration, we’ll walk through how to call this API using ready-to-run Python code examples. Before taking the below steps, however, you should first register a free account on our website to get the necessary API key to authenticate the operation (we’ll explain where to include that below).
For our first step, let’s install the Python SDK:
pip install cloudmersive-image-api-client
Then, let’s include the imports:
from __future__ import print_function
from cloudmersive_image_api_client.rest import ApiException
from pprint import pprint
Now it’s time to include the API key authorization snippet & fill that in. After that, copy in the rest of the code & configure your parameters before calling the API:
# 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))
x = 56 # int | Horizontal (X) offset of the drop shadow
y = 56 # int | Vertical (Y) offset of the drop shadow
sigma = 56 # int | Sigma (blur distance) of the drop shadow
opacity = 56 # int | Opacity of the drop shadow; 0 is 0% and 100 is 100%
image_file = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try:
# Add a customizeable drop shadow to an image
api_response = api_instance.edit_drop_shadow(x, y, sigma, opacity, image_file)
except ApiException as e:
print("Exception when calling EditApi->edit_drop_shadow: %s\n" % e)
No more fuss — that’s all the code you’ll need.