How to Create EAN Barcodes in PHP
--
A simple EAN barcode API solution might become a critical factor in scaling your ecommerce business. Thankfully, you can generate both EAN-13 and EAN-8 barcodes with ease using the PHP code examples provided in this article, and you can do so for free with a free-tier API key (get one by registering a free account on our website; this comes with 800 API calls per month and zero commitments).
First, run this command to install the PHP SDK:
composer require cloudmersive/cloudmersive_barcode_api_client
After that, use the below code to create EAN-13 barcodes as PNG files:
<?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\GenerateBarcodeApi(
new GuzzleHttp\Client(),
$config
);
$value = "value_example"; // string | Barcode value to generate from
try {
$result = $apiInstance->generateBarcodeEAN13($value);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling GenerateBarcodeApi->generateBarcodeEAN13: ', $e->getMessage(), PHP_EOL;
}
?>
Or use the final code examples below to create EAN-8 barcodes as PNG files:
<?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\GenerateBarcodeApi(
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;
}
?>
If your barcode generation needs begin to exceed the 800 free API call monthly limit, you can easily upgrade to an enterprise plan through your account page. Simple & easy.