]>
Raphaƫl G. Git Repositories - cdn/blob - vendor/phpqrcode/qrimage.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_IMAGE', true);
29 //----------------------------------------------------------------------
30 public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE, $back_color, $fore_color)
32 $image = self
::image($frame, $pixelPerPoint, $outerFrame, $back_color, $fore_color);
34 if ($filename === false) {
35 Header("Content-type: image/png");
38 if($saveandprint===TRUE){
39 ImagePng($image, $filename);
40 header("Content-type: image/png");
43 ImagePng($image, $filename);
50 //----------------------------------------------------------------------
51 public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
53 $image = self
::image($frame, $pixelPerPoint, $outerFrame);
55 if ($filename === false) {
56 Header("Content-type: image/jpeg");
57 ImageJpeg($image, null, $q);
59 ImageJpeg($image, $filename, $q);
65 //----------------------------------------------------------------------
66 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000)
69 $w = strlen($frame[0]);
71 $imgW = $w +
2*$outerFrame;
72 $imgH = $h +
2*$outerFrame;
74 $base_image =ImageCreate($imgW, $imgH);
76 // convert a hexadecimal color code into decimal format (red = 255 0 0, green = 0 255 0, blue = 0 0 255)
77 $r1 = round((($fore_color & 0xFF0000) >> 16), 5);
78 $g1 = round((($fore_color & 0x00FF00) >> 8), 5);
79 $b1 = round(($fore_color & 0x0000FF), 5);
81 // convert a hexadecimal color code into decimal format (red = 255 0 0, green = 0 255 0, blue = 0 0 255)
82 $r2 = round((($back_color & 0xFF0000) >> 16), 5);
83 $g2 = round((($back_color & 0x00FF00) >> 8), 5);
84 $b2 = round(($back_color & 0x0000FF), 5);
88 $col[0] = ImageColorAllocate($base_image, $r2, $g2, $b2);
89 $col[1] = ImageColorAllocate($base_image, $r1, $g1, $b1);
91 imagefill($base_image, 0, 0, $col[0]);
93 for($y=0; $y<$h; $y++
) {
94 for($x=0; $x<$w; $x++
) {
95 if ($frame[$y][$x] == '1') {
96 ImageSetPixel($base_image,$x+
$outerFrame,$y+
$outerFrame,$col[1]);
101 $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
102 ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
103 ImageDestroy($base_image);
105 return $target_image;