Skip to content

Instantly share code, notes, and snippets.

@ano
Created November 28, 2017 05:28
Show Gist options
  • Save ano/d8ffdf224a09990ba10dba6e2a3e6a57 to your computer and use it in GitHub Desktop.
Save ano/d8ffdf224a09990ba10dba6e2a3e6a57 to your computer and use it in GitHub Desktop.
Viviki: QR Code + Logo Generator that accepts a form_id and entry_id parameter and creates a QRCode Link from that.
<?php
/**
* QR Code + Logo Generator
*
* Description: Accepts a form_id and entry_id parameter and creates a QRCode Link from that.
* Author: Ano Tisam
* Email: an0tis@gmail.com
* Orginal: https://gist.github.com/NTICompass/1283249
*/
define("DOMAIN","https://www.govcrate.com/forms/v6/view_entry.php");
if(isset($_GET["form_id"]) && isset($_GET["entry_id"])){
createQRCode($_GET["form_id"], $_GET["entry_id"]);
}
else{
header('Content-type: application/json');
echo json_encode(array("error" => "Error, make sure form_id and entry_id parameters are set."));
}
function createQRCode($form_id, $entry_id ){
$data = DOMAIN . "?form_id={$form_id}&entry_id={$entry_id}";
$size = isset($_GET['size']) ? $_GET['size'] : '256x256';
$logo = isset($_GET['logo']) ? $_GET['logo'] : 'logo.png';
header('Content-type: image/png');
$QR = imagecreatefrompng('https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs='.$size.'&chl='.urlencode($data));
if($logo !== FALSE){
$logo = imagecreatefromstring(file_get_contents($logo));
$QR_width = imagesx($QR);
$QR_height = imagesy($QR);
$logo_width = imagesx($logo);
$logo_height = imagesy($logo);
// Scale logo to fit in the QR Code
$logo_qr_width = $QR_width/3;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
imagecopyresampled($QR, $logo, $QR_width/3, $QR_height/3, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
}
imagepng($QR);
imagedestroy($QR);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment