How to generate a QR code barcode as a PNG file in PHP

Generating a QR code is a hassle to do from scratch. Luckily, there is an API for that. Simply install our Barcode API…

"require": {
"cloudmersive/cloudmersive_barcode_api_client": "^1.4"

…call generateBarcodeQRCode…

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(),
$value = "value_example"; // string | QR code text to convert into the QR code barcode
try {
$result = $apiInstance->generateBarcodeQRCode($value);
} catch (Exception $e) {
echo 'Exception when calling GenerateBarcodeApi->generateBarcodeQRCode: ', $e->getMessage(), PHP_EOL;

…and you’re done! This function will supply you with a QR code as a PNG. If you need support for other barcode types such as UPC-A 1D, check out the other functions available in the Barcode API.

Written by

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