How to generate a EAN-8 barcode as a PNG file in PHP

Prepare to be amazed at how easy it is to create a barcode in EAN-8 format. To start, simply install our barcode API client by running this in Composer’s command line:

composer require cloudmersive/cloudmersive_barcode_api_client

Then call generateBarcodeEAN8 with your desired barcode value:

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(),
$value = "value_example"; // string | Barcode value to generate from
try {
$result = $apiInstance->generateBarcodeEAN8($value);
} catch (Exception $e) {
echo 'Exception when calling GenerateBarcodeApi->generateBarcodeEAN8: ', $e->getMessage(), PHP_EOL;

And you will be left with your barcode in PNG format, simple as that. If you work with a variety of barcode formats or use QR codes, our API supports those as well.

Image for post
Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

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