Source of file api.barcodeqr.php
Size: 3,666 Bytes - Last Modified: 2024-04-27T15:26:05+03:00
/tmp/current_snapshot/api/libs/api.barcodeqr.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 | <?php /** * BarcodeQR - Code QR Barcode Image Generator (PNG) * * @package BarcodeQR * @category BarcodeQR * @name BarcodeQR * @version 1.0 * @author Shay Anderson 05.11 * @link http://www.shayanderson.com/php/php-qr-code-generator-class.htm * @license http://www.gnu.org/licenses/gpl.html GPL License * This is free software and is distributed WITHOUT ANY WARRANTY */ final class BarcodeQR { /** * Chart API URL */ const API_CHART_URL = "http://chart.apis.google.com/chart"; /** * Code data * * @var string $_data */ private $_data; /** * Bookmark code * * @param string $title * @param string $url */ public function bookmark($title = null, $url = null) { $this->_data = "MEBKM:TITLE:{$title};URL:{$url};;"; } /** * MECARD code * * @param string $name * @param string $address * @param string $phone * @param string $email */ public function contact($name = null, $address = null, $phone = null, $email = null) { $this->_data = "MECARD:N:{$name};ADR:{$address};TEL:{$phone};EMAIL:{$email};;"; } /** * Create code with GIF, JPG, etc. * * @param string $type * @param string $size * @param string $content */ public function content($type = null, $size = null, $content = null) { $this->_data = "CNTS:TYPE:{$type};LNG:{$size};BODY:{$content};;"; } /** * Generate QR code image * * @param int $size * @param string $filename * @return bool */ public function draw($size = 150, $filename = null, $returnRawImgData = false) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, self::API_CHART_URL); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, "chs={$size}x{$size}&cht=qr&chl=" . urlencode($this->_data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $img = curl_exec($ch); curl_close($ch); if($img) { if ($filename) { if (!preg_match("#\.png$#i", $filename)) { $filename .= ".png"; } return file_put_contents($filename, $img); } elseif ($returnRawImgData) { return ($img); } else { header("Content-type: image/png"); print $img; return true; } } return false; } /** * Email address code * * @param string $email * @param string $subject * @param string $message */ public function email($email = null, $subject = null, $message = null) { $this->_data = "MATMSG:TO:{$email};SUB:{$subject};BODY:{$message};;"; } /** * Geo location code * * @param string $lat * @param string $lon * @param string $height */ public function geo($lat = null, $lon = null, $height = null) { $this->_data = "GEO:{$lat},{$lon},{$height}"; } /** * Telephone number code * * @param string $phone */ public function phone($phone = null) { $this->_data = "TEL:{$phone}"; } /** * SMS code * * @param string $phone * @param string $text */ public function sms($phone = null, $text = null) { $this->_data = "SMSTO:{$phone}:{$text}"; } /** * Text code * * @param string $text */ public function text($text = null) { $this->_data = $text; } /** * URL code * * @param string $url */ public function url($url = null) { $this->_data = preg_match("#^https?\:\/\/#", $url) ? $url : "http://{$url}"; } /** * Wifi code * * @param string $type * @param string $ssid * @param string $password */ public function wifi($type = null, $ssid = null, $password = null) { $this->_data = "WIFI:T:{$type};S{$ssid};{$password};;"; } } ?> |