How to Generate an Image of Handwriting From Text Input with Java
--
Pretty amazing what you can do with Deep Learning, right? Our Handwriting API can take input text and return a PNG file with “Handwritten” text specified in the input parameters. You can also specify the target width & stroke width for the handwriting.
You can use this API for free by following instructions below to implement ready-to-run code in Java, and creating a free account on our website (Home — Cloudmersive APIs) to receive your Cloudmersive API key.
Kick things off by installing the Java SDK with Maven. First, add a reference to the repository found in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next, add one to the dependency found in pom.xml:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
Lastly, include the import classes and call the image processing function:
// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.TextGenerationApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");TextGenerationApi apiInstance = new TextGenerationApi();
CreateHandwritingRequest request = new CreateHandwritingRequest(); // CreateHandwritingRequest | Draw text parameters
try {
Object result = apiInstance.textGenerationCreateHandwritingPng(request);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling TextGenerationApi#textGenerationCreateHandwritingPng");
e.printStackTrace();
}
And just like that, you’re all done.