* * 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) { $vect = self::vectEPS($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color); if ($filename === false) { header("Content-Type: application/postscript"); header('Content-Disposition: filename="qrcode.eps"'); return $vect; } else { if($saveandprint===TRUE){ QRtools::save($vect, $filename); header("Content-Type: application/postscript"); header('Content-Disposition: filename="'.$filename.'"'); return $vect; }else{ QRtools::save($vect, $filename); } } } //---------------------------------------------------------------------- private static function vectEPS($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; // 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 = $r.' '.$b.' '.$g; // 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 = $r.' '.$b.' '.$g; $output = '%!PS-Adobe EPSF-3.0'."\n". '%%Creator: Zend_Matrixcode_Qrcode'."\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.' setrgbcolor'."\n"; $output .= '-'.$outerFrame.' -'.$outerFrame.' '.($w + 2*$outerFrame).' '.($h + 2*$outerFrame).' F'."\n"; // set the symbol color $output .= $fore_color.' setrgbcolor'."\n"; // 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: filename="qrcode.svg"'); return $vect; } else { if($saveandprint===TRUE){ QRtools::save($vect, $filename); header("Content-Type: image/svg+xml"); header('Content-Disposition: filename="'.$filename.'"'); return $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 = dechex($back_color); $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; } }