* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ define('QR_VECT', true); class QRvect { //---------------------------------------------------------------------- public static function eps($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) { $vect = self::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color, $cmyk); if ($filename === false) { header("Content-Type: application/postscript"); header('Content-Disposition: filename="qrcode.eps"'); echo $vect; } else { if($saveandprint===TRUE){ QRtools::save($vect, $filename); header("Content-Type: application/postscript"); header('Content-Disposition: filename="qrcode.eps"'); echo $vect; }else{ QRtools::save($vect, $filename); } } } //---------------------------------------------------------------------- private static function vectEPS($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false) { $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2*$outerFrame; $imgH = $h + 2*$outerFrame; if ($cmyk) { // convert color value into decimal eps format $c = round((($fore_color & 0xFF000000) >> 16) / 255, 5); $m = round((($fore_color & 0x00FF0000) >> 16) / 255, 5); $y = round((($fore_color & 0x0000FF00) >> 8) / 255, 5); $k = round(($fore_color & 0x000000FF) / 255, 5); $fore_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n"; // convert color value into decimal eps format $c = round((($back_color & 0xFF000000) >> 16) / 255, 5); $m = round((($back_color & 0x00FF0000) >> 16) / 255, 5); $y = round((($back_color & 0x0000FF00) >> 8) / 255, 5); $k = round(($back_color & 0x000000FF) / 255, 5); $back_color_string = $c.' '.$m.' '.$y.' '.$k.' setcmykcolor'."\n"; } else { // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) $r = round((($fore_color & 0xFF0000) >> 16) / 255, 5); $b = round((($fore_color & 0x00FF00) >> 8) / 255, 5); $g = round(($fore_color & 0x0000FF) / 255, 5); $fore_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n"; // convert a hexadecimal color code into decimal eps format (green = 0 1 0, blue = 0 0 1, ...) $r = round((($back_color & 0xFF0000) >> 16) / 255, 5); $b = round((($back_color & 0x00FF00) >> 8) / 255, 5); $g = round(($back_color & 0x0000FF) / 255, 5); $back_color_string = $r.' '.$b.' '.$g.' setrgbcolor'."\n"; } $output = '%!PS-Adobe EPSF-3.0'."\n". '%%Creator: PHPQrcodeLib'."\n". '%%Title: QRcode'."\n". '%%CreationDate: '.date('Y-m-d')."\n". '%%DocumentData: Clean7Bit'."\n". '%%LanguageLevel: 2'."\n". '%%Pages: 1'."\n". '%%BoundingBox: 0 0 '.$imgW * $pixelPerPoint.' '.$imgH * $pixelPerPoint."\n"; // set the scale $output .= $pixelPerPoint.' '.$pixelPerPoint.' scale'."\n"; // position the center of the coordinate system $output .= $outerFrame.' '.$outerFrame.' translate'."\n"; // redefine the 'rectfill' operator to shorten the syntax $output .= '/F { rectfill } def'."\n"; // set the symbol color $output .= $back_color_string; $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2*$outerFrame).' '.($h + 2*$outerFrame).' F'."\n"; // set the symbol color $output .= $fore_color_string; // Convert the matrix into pixels for($i=0; $i<$h; $i++) { for($j=0; $j<$w; $j++) { if( $frame[$i][$j] == '1') { $y = $h - 1 - $i; $x = $j; $output .= $x.' '.$y.' 1 1 F'."\n"; } } } $output .='%%EOF'; return $output; } //---------------------------------------------------------------------- public static function svg($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color) { $vect = self::vectSVG($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color); if ($filename === false) { header("Content-Type: image/svg+xml"); //header('Content-Disposition: attachment, filename="qrcode.svg"'); echo $vect; } else { if($saveandprint===TRUE){ QRtools::save($vect, $filename); header("Content-Type: image/svg+xml"); //header('Content-Disposition: filename="'.$filename.'"'); echo $vect; }else{ QRtools::save($vect, $filename); } } } //---------------------------------------------------------------------- private static function vectSVG($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000) { $h = count($frame); $w = strlen($frame[0]); $imgW = $w + 2*$outerFrame; $imgH = $h + 2*$outerFrame; $output = ''."\n". ''."\n". ''."\n"; $output = ''."\n". ''."\n". ''."\n". ''."\n"; if(!empty($back_color)) { $backgroundcolor = str_pad(dechex($back_color), 6, "0", STR_PAD_LEFT); $output .= ''."\n"; } $output .= ''."\n". ''."\n". ''."\n". ''."\n"; // Convert the matrix into pixels for($i=0; $i<$h; $i++) { for($j=0; $j<$w; $j++) { if( $frame[$i][$j] == '1') { $y = ($i + $outerFrame) * $pixelPerPoint; $x = ($j + $outerFrame) * $pixelPerPoint; $output .= ''."\n"; } } } $output .= ''."\n". ''; return $output; } }