Transform an Image into an Artistic Painting Automatically in Python
Sometimes, even when photos are taken with the best cameras, they can just look… boring. If you want to spice them up a little, there’s an API for that: the Cloudmersive Image API enables you to transform an image into a digital artistic painting. You can choose from a few different styles, like “udnie” or “wave” or “rain_princess.” It’s easy to connect with this API using copy & paste code in 13+ programming languages via the Cloudmersive API console. In this article, we’ll walk through how to connect in Python.
To begin, you’ll first need to install the Python SDK & kickoff the callback function with the below code:
pip install cloudmersive-image-api-clientfrom __future__ import print_function
import time
import cloudmersive_image_api_client
from cloudmersive_image_api_client.rest import ApiException
from pprint import pprint
The next step is to authenticate your Cloudmersive API key. You can copy your key into the below string (and if you don’t have a key, you can easily acquire one by making a free account on the Cloudmersive website):
# Configure API key authorization: Apikey
configuration = cloudmersive_image_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
Finally, you can complete the callback function with this final snippet:
# create an instance of the API class
api_instance = cloudmersive_image_api_client.ArtisticApi(cloudmersive_image_api_client.ApiClient(configuration))
style = 'style_example' # str | The style of the painting to apply. To start, try \"udnie\" a painting style. Possible values are: \"udnie\", \"wave\", \"la_muse\", \"rain_princess\".
image_file = '/path/to/inputfile' # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try:
# Transform an image into an artistic painting automatically
api_response = api_instance.artistic_painting(style, image_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ArtisticApi->artistic_painting: %s\n" % e)