Create an Image of Handwriting in PNG Format in Python

A handwritten note is always more meaningful than reading a block of computer text, even if it’s not YOUR handwriting. If you’re creating thank you notes, Christmas cards, etc. at scale, writing things by hand can be a bit overwhelming. Thankfully, there’s an API to take some of that burden off your hands. With the Cloudmersive Image API, you can generate realistic handwriting from an input block of text and return the result as a PNG image. It’s easy to leverage this API in your application with ready-to-run code from the Cloudmersive API Console. Let’s look at how you can connect in Python.

First, you’ll need to use the below command to install the Python SDK:

pip install cloudmersive-image-api-client

Next, you can kickoff the API call function with the next two code snippets. Make sure to authenticate your API key in the second snippet:

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'

Finally, it’s time to wrap up the function. Use the below code to call the API and return your handwritten text:

# create an instance of the API class
api_instance = cloudmersive_image_api_client.TextGenerationApi(cloudmersive_image_api_client.ApiClient(configuration))
request = cloudmersive_image_api_client.CreateHandwritingRequest() # CreateHandwritingRequest | Draw text parameters
try:
# Create an image of handwriting in PNG format
api_response = api_instance.text_generation_create_handwriting_png(request)
pprint(api_response)
except ApiException as e:
print("Exception when calling TextGenerationApi->text_generation_create_handwriting_png: %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