Skip to content

Instantly share code, notes, and snippets.

@aamnah
Created April 4, 2015 10:05
Show Gist options
  • Save aamnah/9ad64398f2d58c345b74 to your computer and use it in GitHub Desktop.
Save aamnah/9ad64398f2d58c345b74 to your computer and use it in GitHub Desktop.
Generate a QR code using Google Charts API
<?php
// Source: http://stackoverflow.com/questions/5943368/dynamically-generating-a-qr-code-with-php
// Google Charts Documentation: https://developers.google.com/chart/infographics/docs/qr_codes?csw=1#overview
// CHart Type
$cht = "qr";
// CHart Size
$chs = "300x300";
// CHart Link
// the url-encoded string you want to change into a QR code
$chl = urlencode("http://aamnah.com");
// CHart Output Encoding (optional)
// default: UTF-8
$choe = "UTF-8";
$qrcode = 'https://chart.googleapis.com/chart?cht=' . $cht . '&chs=' . $chs . '&chl=' . $chl . '&choe=' . $choe;
echo $qrcode . '<br>';
?>
<img src="<?php echo $qrcode ?>" alt="My QR code">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment