Last active
August 29, 2015 14:12
-
-
Save OjosAlertaAC/266df2907e9e0e7638df to your computer and use it in GitHub Desktop.
Some routines to save a qr code in gif format
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
<?Php | |
/* Alfonso Orozco Aguilar for Ojos Alerta AC - ojosalerta.org | |
Using LGPL 2.0 Exclusively | |
https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html | |
Original version: 18/dic/2013 | |
Comments to : github(nospam)@alfonsoorozco.com | |
The purpose of this file is give an example of easy create a qr code | |
for be used in a printed report. One of my customers had a solution but | |
was not resizable. I make these routines but really | |
the qr was not needed, and i suggest use a code39 instead and if google | |
apps drop support, i go to do so.. | |
The interesting part of this snippet is the solution if our customer | |
need save the image in gif format instead, then i dont use google. | |
Example: | |
In other instances i use qrcode library instead google because i save to png | |
//QRcode::png('code data text', 'output.png'); // creates file | |
QRcode::png($theurl, "$aleat.png", QR_ECLEVEL_H, 7); // 7 is the size | |
*/ | |
echo printQRCode ("http://www.ojosalerta.org"); | |
function printQRCode ( $url , $size = 100) { | |
/* if u go to save the file, use this instead google !!!! | |
QRcode::png('code data text', 'output.png'); // creates file | |
QRcode::png($theurl, "$random.png", QR_ECLEVEL_H, 7); // 7 is the size | |
*/ | |
$newurl="http://chart.apis.google.com/chart?chs=$size"."x$size&cht=qr&chl=". urlencode ( $url ); | |
return "<img src = '$newurl' />"; | |
} | |
function semirandom(){ | |
//we define a random/base string, i suggest dont use special chars | |
$stri = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; | |
//get length | |
$ourlen=strlen($stri); | |
//define a variable to hold the semirandom | |
$pass = ""; | |
//we use 10 to length | |
$passlen=10; | |
//create password | |
for($i=1 ; $i<=$passlen ; $i++){ | |
//random between 0 and ourlen -1 | |
$pos=rand(0,$ourlen-1); | |
$pass .= substr($stri,$pos,1); // iterate | |
} | |
return $pass; | |
} // semirandom | |
function png2gif($thepngfilename){ | |
/* if u go to save the file, use this instead google !!!! | |
QRcode::png('code data text', 'output.png'); // creates file | |
QRcode::png($theurl, "$random.png", QR_ECLEVEL_H, 7); // 7 is the size | |
*/ | |
// Load the PNG | |
$png = imagecreatefrompng($thepngfilename); | |
// Save the image as a GIF | |
$gif_filename=str_replace(".png",".gif",strtolower($thepngfilename)); | |
imagegif($png, $gif_filename); | |
// Free from memory | |
imagedestroy($png); | |
unlink($thepngfilename); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment