private function createQRCode($url, $filename) { $enc = QRencode::factory(); $enc->size = 17; $enc->margin = 2; # bug! $enc->fore_color = 0x101010; return $enc->encodeSVG($url, $filename); }
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; }
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); }
/** * 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);
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; }
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); }
/** 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; }
$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()); }
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); }