How to generate a UPC-E barcode as a PNG file in PHP
1 min readAug 6, 2019
Let’s keep this as simple as we possibly can.
Start by running the following snippet in the command line of Composer:
composer require cloudmersive/cloudmersive_barcode_api_client
Then call generateBarcodeUPCE as seen below:
<?php
require_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\GenerateBarcodeApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$value = "value_example"; // string | UPC-E barcode value to generate fromtry {
$result = $apiInstance->generateBarcodeUPCE($value);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling GenerateBarcodeApi->generateBarcodeUPCE: ', $e->getMessage(), PHP_EOL;
}
?>
And you will get your entered value as a barcode PNG. Easy.