Skip to content

Instantly share code, notes, and snippets.

@hengkiardo
Created November 25, 2012 03:01
Show Gist options
  • Save hengkiardo/4142221 to your computer and use it in GitHub Desktop.
Save hengkiardo/4142221 to your computer and use it in GitHub Desktop.
QR Code for the Current URL with PHP and Google Charts
function saveImage($your_url, $width, $height, $file) {
$your_url = urlencode($your_url);
$url = 'http://chart.apis.google.com/chart?chs='.$width.'x'.$height.'&cht=qr&chl='.$your_url';
// initialize cURL settings
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// fetch raw data
$rawdata = curl_exec($ch);
curl_close($ch);
// convert it to a GD image and save
$img = imagecreatefromstring($rawdata);
/* your image saving functions come here */
imagedestroy($img);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment