Created
November 25, 2012 03:01
-
-
Save hengkiardo/4142221 to your computer and use it in GitHub Desktop.
QR Code for the Current URL with PHP and Google Charts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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