How to generate a UPC-A barcode as a PNG file in PHP

Cloudmersive
1 min readAug 6, 2019

--

This method for generating UPC-A barcodes is so easy that if you blink you might miss it. But seriously, it’s just two steps.

Run the following in the command line of Composer:

composer require cloudmersive/cloudmersive_barcode_api_client

Now just call generateBarcodeUPCA:

<?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-A barcode value to generate from
try {
$result = $apiInstance->generateBarcodeUPCA($value);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling GenerateBarcodeApi->generateBarcodeUPCA: ', $e->getMessage(), PHP_EOL;
}
?>

So simple. If you need support for other barcode formats or QR codes, take a look at our documentation to see what our barcode API can do.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet