How to Generate Handwritten Text Images with Deep Learning AI using PHP
Sometimes, rich text fonts don’t match the natural aesthetic we’re looking for. Thankfully, using the ready-to-run PHP code examples below, you can quickly take advantage of our Handwriting API which uses Deep Learning AI to generate realistic handwriting in PNG format. You can specify the target width, stroke width and color value of each request to customize outputs with ease.
To use this API for free, you’ll first need to register a free account on our website. This will generate a free-tier API key which you can use to authenticate your requests.
To install the SDK, first run the following command:
composer require cloudmersive/cloudmersive_imagerecognition_api_client
After that, use the below code examples to structure your API call:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\TextGenerationApi(
new GuzzleHttp\Client(),
$config
);
$request = new \Swagger\Client\Model\CreateHandwritingRequest(); // \Swagger\Client\Model\CreateHandwritingRequest | Draw text parameters
try {
$result = $apiInstance->textGenerationCreateHandwritingPng($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TextGenerationApi->textGenerationCreateHandwritingPng: ', $e->getMessage(), PHP_EOL;
}
?>
Now you can generate images of handwritten text on demand. Nice and simple!