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

Cloudmersive
1 min readAug 6, 2019

--

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:

<?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 | Barcode value to generate from
try {
$result = $apiInstance->generateBarcodeEAN8($value);
print_r($result);
} 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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet