示例#1
0
function qrencode($s, $size = 1, $quality = 'M', $fg = false, $bg = false, $margin = 0)
{
    $ql = array('L' => QR_ECLEVEL_L, 'M' => QR_ECLEVEL_M, 'Q' => QR_ECLEVEL_Q, 'H' => QR_ECLEVEL_H);
    if (!$s or !is_numeric($size) or !is_numeric($margin) or !$quality or !array_key_exists($quality, $ql) or $fg and !validate_color($fg) or $bg and !validate_color($bg)) {
        return false;
    }
    if ($size < 1) {
        $size = 1;
    }
    if ($margin < 0) {
        $margin = 0;
    }
    $q = $ql[$quality];
    $frame = @QRcode::text($s, false, $q, 1, 0);
    if (!$frame) {
        return false;
    }
    $h = count($frame);
    $w = strlen($frame[0]);
    $img = imagecreatetruecolor($w + 2 * $margin, $h);
    $qrimg = imagecreatetruecolor($w * $size + 2 * $margin, $h * $size + 2 * $margin);
    if ($bg) {
        $rgb = str_split($bg[0] == '#' ? substr($bg, 1, 6) : $bg, 2);
        $r = hexdec($rgb[0]);
        $g = hexdec($rgb[1]);
        $b = hexdec($rgb[2]);
    } else {
        $r = $g = $b = 255;
    }
    $bg = imagecolorallocate($img, $r, $g, $b);
    imagefill($img, 0, 0, $bg);
    $bg = imagecolorallocate($qrimg, $r, $g, $b);
    imagefill($qrimg, 0, 0, $bg);
    if ($fg) {
        $rgb = str_split($fg[0] == '#' ? substr($fg, 1, 6) : $fg, 2);
        $r = hexdec($rgb[0]);
        $g = hexdec($rgb[1]);
        $b = hexdec($rgb[2]);
    } else {
        $r = $g = $b = 0;
    }
    $fg = imagecolorallocate($img, $r, $g, $b);
    for ($y = 0; $y < $h; $y++) {
        for ($x = 0; $x < $w; $x++) {
            if ($frame[$y][$x] == '1') {
                imagesetpixel($img, $x, $y, $fg);
            }
        }
    }
    imagecopyresized($qrimg, $img, $margin, $margin, 0, 0, $w * $size, $h * $size, $w, $h);
    imagedestroy($img);
    ob_start();
    imagepng($qrimg);
    $png = ob_get_clean();
    imagedestroy($qrimg);
    return $png;
}
示例#2
0
 public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
 {
     $barcode_array = array();
     if (!is_array($mode)) {
         $mode = explode(',', $mode);
     }
     $eccLevel = 'L';
     if (count($mode) > 1) {
         $eccLevel = $mode[1];
     }
     $qrTab = QRcode::text($code, false, $eccLevel);
     $size = count($qrTab);
     $barcode_array['num_rows'] = $size;
     $barcode_array['num_cols'] = $size;
     $barcode_array['bcode'] = array();
     foreach ($qrTab as $line) {
         $arrAdd = array();
         foreach (str_split($line) as $char) {
             $arrAdd[] = $char == '1' ? 1 : 0;
         }
         $barcode_array['bcode'][] = $arrAdd;
     }
     return $barcode_array;
 }
 /**
  * @phutil-external-symbol class QRcode
  */
 private function renderQRCode($uri)
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/externals/phpqrcode/phpqrcode.php';
     $lines = QRcode::text($uri);
     $total_width = 240;
     $cell_size = floor($total_width / count($lines));
     $rows = array();
     foreach ($lines as $line) {
         $cells = array();
         for ($ii = 0; $ii < strlen($line); $ii++) {
             if ($line[$ii] == '1') {
                 $color = '#000';
             } else {
                 $color = '#fff';
             }
             $cells[] = phutil_tag('td', array('width' => $cell_size, 'height' => $cell_size, 'style' => 'background: ' . $color), '');
         }
         $rows[] = phutil_tag('tr', array(), $cells);
     }
     return phutil_tag('table', array('style' => 'margin: 24px auto;'), $rows);
 }
示例#4
0
</td>
  </tr>
  <tr border="0">
    <td colspan="6">Diagnostico:</td>
  </tr>
  <tr border="0">
    <td height="95" colspan="6">
    <div style="float:left;">
   <!--[if (IE )]>
   	<?php 
// print_r('menor o igual a 8');
include '../autogestion/qrcode/qrlib.php';
// text output   ie8 o inferior
$codeContents = $numero_orden . ' 22';
// generating
$text = QRcode::text($codeContents);
$raw = join("<br/>", $text);
$raw = strtr($raw, array('0' => '<span style="color:white">&#9608;&#9608;</span>', '1' => '&#9608;&#9608;'));
echo '<tt style="font-size:3px">' . $raw . '</tt>';
?>
   <![endif]-->
   
<!--[if !IE]><!-->
		<?php 
echo '<img  src="qr.php" />';
//<![endif]-->
?>
    <!-- <![endif]-->

    </div>
    <div style="float:right">
示例#5
0
 public static function qrtest()
 {
     // Include only this file, remaining required files will be included from it
     if (!class_exists("qrstr", FALSE)) {
         require_once PATH_PHPQRCODE . "/qrlib.php";
     }
     //write code into file, Error corection lecer is lowest, L (one form: L,M,Q,H)
     //each code square will be 4x4 pixels (4x zoom)
     //code will have 2 code squares white boundary around
     if (1) {
         // Error correction level L : About 7% or less errors can be corrected.
         // Error correction level M : About 15% or less errors can be corrected.
         // Error correction level Q : About 25% or less errors can be corrected.
         // Error correction level H : About 30% or less errors can be corrected.
         $text = "http://www.nordita.org/guest/";
         $filetype = "png";
         // "png","svg","eps","txt"
         if (!in_array($filetype, array("png", "svg", "eps", "txt"))) {
             return FALSE;
         }
         $level = "H";
         // "L" (default) ,"M", "Q", "H"
         $pixelsize = 16;
         // pixel size of each code square
         $margin = 4;
         // boundary width in number of code squares
         $saveandprint = FALSE;
         // TRUE = save to file and display in browser; FALSE = save to file only; redundant if $outfile=FALSE
         $back_color = 0xffffff;
         $fore_color = 0x0;
         $cmyk = TRUE;
         $filename = "qrcode";
         $outfile = PATH_PHPQRCACHE . $filename . "." . $filetype;
         // full file path or FALSE (only output on screen)
         //$outfile      = FALSE;
         switch ($filetype) {
             case "png":
                 QRcode::png($text, $outfile, $level, $pixelsize, $margin, $saveandprint, $back_color, $fore_color);
                 break;
             case "eps":
                 QRcode::eps($text, $outfile, $level, $pixelsize, $margin, $saveandprint, $back_color, $fore_color, $cmyk);
                 break;
             case "svg":
                 QRcode::svg($text, $outfile, $level, $pixelsize, $margin, $saveandprint, $back_color, $fore_color);
                 break;
             case "txt":
                 QRcode::text($text, $outfile, $level, $pixelsize, $margin);
                 // black = "1", white = "0"
                 break;
         }
         // end switch
     }
     //same as above but outputs file directly into browser (with appr. header etc.)
     //all other settings are default
     //WARNING! it should be FIRST and ONLY output generated by script, otherwise
     //rest of output will land inside PNG binary, breaking it for sure
     if (0) {
         QRcode::png("PHP QR Code :)");
     }
     //show benchmark
     if (0) {
         QRtools::timeBenchmark();
     }
     //rebuild cache
     if (0) {
         QRtools::buildCache();
     }
     //code generated in text mode - as a binary table
     //then displayed out as HTML using Unicode block building chars :)
     if (0) {
         $qr = new QRencode();
         $tab = $qr->encode('PHP QR Code :)');
         QRspec::debug($tab, true);
     }
 }
示例#6
0
 private function qrImg($orderid)
 {
     include Doo::conf()->SITE_PATH . 'protected/module/default/class/phpqrcode/qrlib.php';
     $codeContents = $orderid;
     $tempDir = Doo::conf()->QR_FILE_PATH;
     $fileName = $orderid . '.jpg';
     $outerFrame = 0;
     $pixelPerPoint = 5;
     $jpegQuality = 95;
     // generating frame
     $frame = QRcode::text($codeContents, false, QR_ECLEVEL_M);
     // rendering frame with GD2 (that should be function by real impl.!!!)
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 3 * $outerFrame;
     $imgH = $h + 3 * $outerFrame;
     $base_image = imagecreate($imgW, $imgH);
     $col[0] = imagecolorallocate($base_image, 255, 255, 255);
     // BG, white
     $col[1] = imagecolorallocate($base_image, 0, 0, 0);
     // FG, black blue
     imagefill($base_image, 0, 0, $col[0]);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 imagesetpixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     // saving to file
     $target_image = imagecreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     imagecopyresized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     imagedestroy($base_image);
     imagejpeg($target_image, $tempDir . $fileName, $jpegQuality);
     imagedestroy($target_image);
     // displaying
     $qrImg = '<img src="' . Doo::conf()->QR_URL_PATH . $fileName . '" />';
     return $qrImg;
 }
示例#7
0
function checkCode($phone)
{
    $len = strlen($phone);
    $phoneWithCode = "+91-";
    if ($len > 10) {
        for ($i = $len - 10; $i < $len; $i++) {
            $phoneWithCode .= $phone[$i];
        }
    } else {
        $phoneWithCode .= $phone;
    }
    return $phoneWithCode;
}
$length = strlen($_POST['userID']);
$link = 'www.makeadiff.in/volunteer/' . $_POST['userID'];
$frame = QRcode::text($link, false, QR_ECLEVEL_L, 4, 0);
$qrcode = get_qrcode($frame);
$idNumber = (string) $_POST['userID'];
$idSixLength = appendZeros($idNumber, $length);
//echo $idSixLength;
ImageTtfText($im, 13, 0, 15, 343, $black, "fonts/BebasNeue-webfont.ttf", $_POST['Post']);
ImageTtfText($im, 15, 0, 48, 382, $black, "fonts/univers.ttf", $phoneNumberAppended);
ImageTtfText($im, 15, 0, 48, 410, $black, "fonts/univers.ttf", $_POST['Email']);
ImageTtfText($im, 13, 0, 637, 324, $madRed, "fonts/BebasNeue-webfont.ttf", "MAD ID : ");
ImageTtfText($im, 13, 0, 682, 324, $madRed, "fonts/BebasNeue-webfont.ttf", $idSixLength);
ImageTtfText($im, 15, 0, 48, 432, $black, "fonts/univers.ttf", $link);
imagecopyresampled($im, $qrcode, 637, 336, 0, 0, 90, 90, 100, 100);
/*
	Parameters
	1. Final Image
	2. Sampled Image
<?php

include '../lib/full/qrlib.php';
include 'config.php';
// custom code rendering with GD2
// WARNING!!! this is 'bad' example:
// - JPEG is bad choice for QR-Codes (loosy, artifacts...)
// - blue is bad choise for FG color (should make hi contrast with BG color)
$codeContents = '12345';
$tempDir = EXAMPLE_TMP_SERVERPATH;
$fileName = '711_test_custom.jpg';
$outerFrame = 4;
$pixelPerPoint = 5;
$jpegQuality = 95;
// generating frame
$frame = QRcode::text($codeContents, false, QR_ECLEVEL_M);
// rendering frame with GD2 (that should be function by real impl.!!!)
$h = count($frame);
$w = strlen($frame[0]);
$imgW = $w + 2 * $outerFrame;
$imgH = $h + 2 * $outerFrame;
$base_image = imagecreate($imgW, $imgH);
$col[0] = imagecolorallocate($base_image, 255, 255, 255);
// BG, white
$col[1] = imagecolorallocate($base_image, 0, 0, 255);
// FG, blue
imagefill($base_image, 0, 0, $col[0]);
for ($y = 0; $y < $h; $y++) {
    for ($x = 0; $x < $w; $x++) {
        if ($frame[$y][$x] == '1') {
            imagesetpixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);