]>
Raphaƫl G. Git Repositories - cdn/blob - vendor/phpqrcode/qrvect.php
5 * Image output of code using GD2
7 * PHP QR Code is distributed under LGPL 3
8 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 3 of the License, or any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 define('QR_VECT', true);
29 //----------------------------------------------------------------------
30 public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
32 $vect = self
::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color, $cmyk);
34 if ($filename === false) {
35 header("Content-Type: application/postscript");
36 header('Content-Disposition: filename="qrcode.eps"');
39 if($saveandprint===TRUE){
40 QRtools
::save($vect, $filename);
41 header("Content-Type: application/postscript");
42 header('Content-Disposition: filename="qrcode.eps"');
45 QRtools
::save($vect, $filename);
51 //----------------------------------------------------------------------
52 private static function vectEPS($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
55 $w = strlen($frame[0]);
57 $imgW = $w +
2*$outerFrame;
58 $imgH = $h +
2*$outerFrame;
62 // convert color value into decimal eps format
63 $c = round((($fore_color & 0xFF000000) >> 16) / 255, 5);
64 $m = round((($fore_color & 0x00FF0000) >> 16) / 255, 5);
65 $y = round((($fore_color & 0x0000FF00) >> 8) / 255, 5);
66 $k = round(($fore_color & 0x000000FF) / 255, 5);
67 $fore_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n";
69 // convert color value into decimal eps format
70 $c = round((($back_color & 0xFF000000) >> 16) / 255, 5);
71 $m = round((($back_color & 0x00FF0000) >> 16) / 255, 5);
72 $y = round((($back_color & 0x0000FF00) >> 8) / 255, 5);
73 $k = round(($back_color & 0x000000FF) / 255, 5);
74 $back_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n";
78 // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
79 $r = round((($fore_color & 0xFF0000) >> 16) / 255, 5);
80 $b = round((($fore_color & 0x00FF00) >> 8) / 255, 5);
81 $g = round(($fore_color & 0x0000FF) / 255, 5);
82 $fore_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n";
84 // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...)
85 $r = round((($back_color & 0xFF0000) >> 16) / 255, 5);
86 $b = round((($back_color & 0x00FF00) >> 8) / 255, 5);
87 $g = round(($back_color & 0x0000FF) / 255, 5);
88 $back_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n";
92 '%!PS-Adobe EPSF-3.0'."\n".
93 '%%Creator: PHPQrcodeLib'."\n".
94 '%%Title: QRcode'."\n".
95 '%%CreationDate: '.date('Y-m-d')."\n".
96 '%%DocumentData: Clean7Bit'."\n".
97 '%%LanguageLevel: 2'."\n".
99 '%%BoundingBox: 0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint."\n";
102 $output .= $pixelPerPoint.' '.$pixelPerPoint.' scale'."\n";
103 // position the center of the coordinate system
105 $output .= $outerFrame.' '.$outerFrame.' translate'."\n";
110 // redefine the 'rectfill' operator to shorten the syntax
111 $output .= '/F { rectfill } def'."\n";
113 // set the symbol color
114 $output .= $back_color_string;
115 $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w +
2*$outerFrame).' '.($h +
2*$outerFrame).' F'."\n";
118 // set the symbol color
119 $output .= $fore_color_string;
121 // Convert the matrix into pixels
123 for($i=0; $i<$h; $i++
) {
124 for($j=0; $j<$w; $j++
) {
125 if( $frame[$i][$j] == '1') {
128 $output .= $x.' '.$y.' 1 1 F'."\n";
139 //----------------------------------------------------------------------
140 public static function svg($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color)
142 $vect = self
::vectSVG($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color);
144 if ($filename === false) {
145 header("Content-Type: image/svg+xml");
146 //header('Content-Disposition: attachment, filename="qrcode.svg"');
149 if($saveandprint===TRUE){
150 QRtools
::save($vect, $filename);
151 header("Content-Type: image/svg+xml");
152 //header('Content-Disposition: filename="'.$filename.'"');
155 QRtools
::save($vect, $filename);
161 //----------------------------------------------------------------------
162 private static function vectSVG($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000)
165 $w = strlen($frame[0]);
167 $imgW = $w +
2*$outerFrame;
168 $imgH = $h +
2*$outerFrame;
172 '<?xml version="1.0" encoding="utf-8"?>'."\n".
173 '<svg version="1.1" baseProfile="full" width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" viewBox="0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint.'"
174 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events">'."\n".
175 '<desc></desc>'."\n";
178 '<?xml version="1.0" encoding="utf-8"?>'."\n".
179 '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">'."\n".
180 '<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" xmlns:xlink="http://www.w3.org/1999/xlink" width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" viewBox="0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint.'">'."\n".
181 '<desc></desc>'."\n";
183 if(!empty($back_color)) {
184 $backgroundcolor = str_pad(dechex($back_color), 6, "0", STR_PAD_LEFT
);
185 $output .= '<rect width="'.$imgW * $pixelPerPoint.'" height="'.$imgH * $pixelPerPoint.'" fill="#'.$backgroundcolor.'" cx="0" cy="0" />'."\n";
190 '<rect id="p" width="'.$pixelPerPoint.'" height="'.$pixelPerPoint.'" />'."\n".
192 '<g fill="#'.str_pad(dechex($fore_color), 6, "0", STR_PAD_LEFT
).'">'."\n";
195 // Convert the matrix into pixels
197 for($i=0; $i<$h; $i++
) {
198 for($j=0; $j<$w; $j++
) {
199 if( $frame[$i][$j] == '1') {
200 $y = ($i +
$outerFrame) * $pixelPerPoint;
201 $x = ($j +
$outerFrame) * $pixelPerPoint;
202 $output .= '<use x="'.$x.'" y="'.$y.'" xlink:href="#p" />'."\n";