예제 #1
0
파일: qr.php 프로젝트: swindhab/CliqrPlugin
 private function createQRCode($url, $filename)
 {
     $enc = QRencode::factory();
     $enc->size = 17;
     $enc->margin = 2;
     # bug!
     $enc->fore_color = 0x101010;
     return $enc->encodeSVG($url, $filename);
 }
예제 #2
0
파일: qrcode.php 프로젝트: q0821/esportshop
 public function setOptions($level = 0, $pixelPerPoint = 3, $outerFrame = 2, $fgcolor = null, $bgcolor = null)
 {
     $levels = array('l' => 0, 'm' => 1, 'q' => 2, 'h' => 3);
     if (!is_numeric($level)) {
         if (is_string($level) && isset($levels[strtolower($level)])) {
             $level = $levels[strtolower($level)];
         } else {
             $level = 0;
         }
     }
     $this->factory = QRencode::factory($level, $pixelPerPoint, $outerFrame);
     $this->bgcolor = $bgcolor;
     $this->fgcolor = $fgcolor;
     $this->outerFrame = $outerFrame;
 }
예제 #3
0
 public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
 {
     $enc = QRencode::factory($level, $size, $margin);
     return $enc->encodeRAW($text, $outfile);
 }
예제 #4
0
파일: qrencode.php 프로젝트: alaingab/modx
 /**
  * Creates SVG with QR-Code.
  * Simple helper function to create QR-Code SVG with one static call.
  * 
  * @param String $text
  *        	text string to encode
  * @param Boolean $elemId
  *        	(optional) target SVG tag id attribute, if __false__ SVG tag with auto id will be created
  * @param String $outfile
  *        	(optional) output file name, when __false__ file is not saved
  * @param Integer $level
  *        	(optional) error correction level __QR_ECLEVEL_L__, __QR_ECLEVEL_M__, __QR_ECLEVEL_Q__ or __QR_ECLEVEL_H__
  * @param Integer $width
  *        	(optional) SVG element width (sam as height)
  * @param Integer $size
  *        	(optional) pixel size, multiplier for each 'virtual' pixel
  * @param Integer $margin
  *        	(optional) code margin (silent zone) in 'virtual' pixels
  * @param Boolean $compress
  *        	(optional) if __true__, compressed SVGZ (instead plaintext SVG) is saved to file
  * @return String containing SVG tag
  */
 public static function svg($text, $elemId = false, $outFile = false, $level = QR_ECLEVEL_L, $width = false, $size = false, $margin = 4, $compress = false, $back_color = 'transparent', $fore_color = 0x0, $position_color = false, $gradient_color = false, $stroke = false, $support = false)
 {
     $enc = QRencode::factory($level, 1, 0);
     $tab_src = $enc->encode($text, false);
     $area = new QRsvgOutput($tab_src);
     $support_code = "dGhhbmtzX2Zvcl90aGVfYmVlcg==";
     if ($support != false) {
         $support = base64_encode($support);
     }
     // Background Color - Convert a hexadecimal color code into decimal RGB
     if ($back_color != 'transparent') {
         preg_match('/^0x?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i', $back_color, $rgb_color);
         if (count($rgb_color) == 4) {
             $area->back_color = 'rgb(' . intval($rgb_color[1], 16) . ',' . intval($rgb_color[2], 16) . ',' . intval($rgb_color[3], 16) . ')';
         }
         unset($rgb_color);
     } else {
         $area->back_color = $back_color;
     }
     // Foreground Color - convert a hexadecimal color code into decimal RGB
     preg_match('/^0x?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i', $fore_color, $rgb_color);
     if (count($rgb_color) == 4) {
         $area->fore_color = 'rgb(' . intval($rgb_color[1], 16) . ',' . intval($rgb_color[2], 16) . ',' . intval($rgb_color[3], 16) . ')';
     }
     unset($rgb_color);
     // Position Color - convert a hexadecimal color code into decimal RGB
     $area->position_color = $area->fore_color;
     if ($position_color != false && $support_code === $support) {
         preg_match('/^0x?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i', $position_color, $rgb_color);
         if (count($rgb_color) == 4) {
             $area->position_color = 'rgb(' . intval($rgb_color[1], 16) . ',' . intval($rgb_color[2], 16) . ',' . intval($rgb_color[3], 16) . ')';
         }
         unset($rgb_color);
     }
     // Gradient Color - Use gradient color
     $area->gcolor = false;
     if ($gradient_color != false && $support_code === $support) {
         preg_match('/^0x?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i', $gradient_color, $rgb_color);
         if (count($rgb_color) == 4) {
             $area->gcolor = '<defs><linearGradient y2="0%" x2="100%" y1="0%" x1="0%" id="gradient"><stop stop-color="' . $area->fore_color . '" offset="0%"/><stop stop-color="rgb(' . intval($rgb_color[1], 16) . ',' . intval($rgb_color[2], 16) . ',' . intval($rgb_color[3], 16) . ')" offset="100%"/></linearGradient></defs>';
             $area->fore_color = 'rgb(0,0,0)';
         }
         unset($rgb_color);
     }
     // Set stroke
     if ($stroke != false && $support_code === $support) {
         $area->pstyle = 'stroke-width:' . $stroke . ';';
     } else {
         $area->pstyle = 'stroke:none;';
     }
     $area->detectGroups();
     $area->detectAreas();
     if ($elemId === false) {
         $elemId = 'qrcode-' . md5(mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000));
         if ($width == false) {
             if ($size !== false && $size > 0) {
                 $width = ($area->getWidth() + 2 * $margin) * $size;
             } else {
                 $width = ($area->getWidth() + 2 * $margin) * 4;
             }
         }
     }
     $svg = '<svg xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         version="1.1"
         baseProfile="full"
         viewBox="' . -$margin . ' ' . -$margin . ' ' . ($area->getWidth() + $margin * 2) . ' ' . ($area->getWidth() + $margin * 2) . '" 
         width="' . $width . '"
         height="' . $width . '"
         id="' . $elemId . '">' . "\n";
     $svg .= $area->getRawSvg() . '</svg>';
     if ($outFile !== false) {
         $xmlPreamble = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n";
         $svgContent = $xmlPreamble . $svg;
         if ($compress === true) {
             file_put_contents($outFile, gzencode($svgContent));
         } else {
             file_put_contents($outFile, $svgContent);
         }
     }
     return $svg;
 }
        case 3:
            list($R, $G, $B) = array($M, $N, $V);
            break;
        case 4:
            list($R, $G, $B) = array($K, $M, $V);
            break;
        case 5:
        case 6:
            //for when $H=1 is given
            list($R, $G, $B) = array($V, $M, $N);
            break;
    }
    return array($R, $G, $B);
}
// QR code lib area finding
$enc = QRencode::factory($eccLevel, 1, 0);
$tab_src = $enc->encode($codeContents, false);
$area = new QRarea($tab_src);
$area->detectGroups();
$area->detectAreas();
// GD2 magical rendering
$imgW = $area->width;
$imgH = $area->width;
$target_image = imagecreate(($imgW + $marginSize * 2) * $pixelPerPoint, ($imgH + $marginSize * 2) * $pixelPerPoint);
$colBg = imagecolorallocate($target_image, 255, 255, 255);
// BG, white
$colTxt = imagecolorallocate($target_image, 0, 0, 0);
// TXT, black
$colPix = imagecolorallocate($target_image, 40, 40, 40);
// Pixel
$colRect = imagecolorallocate($target_image, 190, 190, 190);
예제 #6
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);
     }
 }
 protected static function _qr_img($data)
 {
     require_once self::$o->core_dir . 'libs/phpqrcode/qrlib.php';
     require_once self::$o->core_dir . 'libs/phpqrcode/qsot-qrimage.php';
     ob_start();
     // create the encoder
     $enc = QRencode::factory('L', 3, 1);
     $outfile = false;
     try {
         // attempt to encode the data
         ob_start();
         $tab = $enc->encode($data);
         $err = ob_get_contents();
         ob_end_clean();
         // log any errors produced
         if ($err != '') {
             QRtools::log($outfile, $err);
         }
         // calculate the dimensions of the image
         $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $enc->margin));
         // render the image
         $img_data = QSOT_QRimage::jpg_base64($tab, 2.5, $enc->margin, 100);
     } catch (Exception $e) {
         $img_data = array('data:image/jpeg;base64,', 0, 0);
         // log any exceptions
         QRtools::log($outfile, $e->getMessage());
     }
     return $img_data;
 }
예제 #8
0
 public static function jpg($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $q = 85, $rgb_color = '0,0,0', $rgb_bg_color = '255,255,255')
 {
     $enc = QRencode::factory($level, $size, $margin);
     return $enc->encodeJPG($text, $outfile, $q, $rgb_color, $rgb_bg_color);
 }
예제 #9
0
<?php

include 'phpqrcode/qrlib.php';
//QRcode::png('some othertext 1234', 'out.png', 'H');
$qr = new QRencode();
$tab = $qr->encode('PHP QR Code :)');
QRspec::debug($tab, true);
예제 #10
0
 /**
 Creates SVG with QR-Code.
 Simple helper function to create QR-Code SVG with one static call.
 @param String $text text string to encode 
 @param Boolean $elemId (optional) target SVG tag id attribute, if __false__ SVG tag with auto id will be created 
 @param String $outfile (optional) output file name, when __false__ file is not saved
 @param Integer $level (optional) error correction level __QR_ECLEVEL_L__, __QR_ECLEVEL_M__, __QR_ECLEVEL_Q__ or __QR_ECLEVEL_H__
 @param Integer $width (optional) SVG element width (sam as height)
 @param Integer $size (optional) pixel size, multiplier for each 'virtual' pixel
 @param Integer $margin (optional) code margin (silent zone) in 'virtual'  pixels
 @param Boolean $compress (optional) if __true__, compressed SVGZ (instead plaintext SVG) is saved to file
 @return String containing SVG tag
 */
 public static function svg($text, $elemId = false, $outFile = false, $level = QR_ECLEVEL_L, $width = false, $size = false, $margin = 4, $compress = false)
 {
     $enc = QRencode::factory($level, 1, 0);
     $tab_src = $enc->encode($text, false);
     $area = new QRsvgOutput($tab_src);
     $area->detectGroups();
     $area->detectAreas();
     if ($elemId === false) {
         $elemId = 'qrcode-' . md5(mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000) . '.' . mt_rand(1000, 1000000));
         if ($width == false) {
             if ($size !== false && $size > 0) {
                 $width = ($area->getWidth() + 2 * $margin) * $size;
             } else {
                 $width = ($area->getWidth() + 2 * $margin) * 4;
             }
         }
     }
     $svg = '<svg xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         version="1.1"
         baseProfile="full"
         viewBox="' . -$margin . ' ' . -$margin . ' ' . ($area->getWidth() + $margin * 2) . ' ' . ($area->getWidth() + $margin * 2) . '" 
         width="' . $width . '"
         height="' . $width . '"
         id="' . $elemId . '">' . "\n";
     $svg .= $area->getRawSvg() . '</svg>';
     if ($outFile !== false) {
         $xmlPreamble = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n";
         $svgContent = $xmlPreamble . $svg;
         if ($compress === true) {
             file_put_contents($outFile, gzencode($svgContent));
         } else {
             file_put_contents($outFile, $svgContent);
         }
     }
     return $svg;
 }
예제 #11
0
            $out[] = '';
        } else {
            $out[] = $matches[0][3];
        }
    }
    return $out;
}
// validate signature
list($key, $salt) = qsot_fetch_defines(array('NONCE_KEY', 'NONCE_SALT'), $d['p']);
$test = sha1($key . @json_encode($d) . $salt);
if ($test != $sig) {
    die($debug ? '<!-- hash mismatch : ' . $sig . ' / ' . $test . ' -->' : '');
}
// end abuse protection
include_once 'qrlib.php';
//QRCode::png($d, false, 'L', 3, 1);
$enc = QRencode::factory('L', 3, 1);
$outfile = false;
try {
    ob_start();
    $tab = $enc->encode($d['d']);
    $err = ob_get_contents();
    ob_end_clean();
    if ($err != '') {
        QRtools::log($outfile, $err);
    }
    $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $enc->margin));
    QRimage::jpg($tab, $outfile, 2.5, $enc->margin, 100);
} catch (Exception $e) {
    QRtools::log($outfile, $e->getMessage());
}
예제 #12
0
 public static function getImage($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false, $back_color = 0xffffff, $fore_color = 0x0)
 {
     $enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color);
     return $enc->getImage($text, $outfile);
 }