]>
Commit | Line | Data |
---|---|---|
fb70f26e AD |
1 | <?php\r |
2 | /*\r | |
3 | * PHP QR Code encoder\r | |
4 | *\r | |
5 | * Image output of code using GD2\r | |
6 | *\r | |
7 | * PHP QR Code is distributed under LGPL 3\r | |
8 | * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r | |
9 | *\r | |
10 | * This library is free software; you can redistribute it and/or\r | |
11 | * modify it under the terms of the GNU Lesser General Public\r | |
12 | * License as published by the Free Software Foundation; either\r | |
13 | * version 3 of the License, or any later version.\r | |
14 | *\r | |
15 | * This library is distributed in the hope that it will be useful,\r | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r | |
18 | * Lesser General Public License for more details.\r | |
19 | *\r | |
20 | * You should have received a copy of the GNU Lesser General Public\r | |
21 | * License along with this library; if not, write to the Free Software\r | |
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r | |
23 | */\r | |
24 | \r | |
25 | define('QR_IMAGE', true);\r | |
26 | \r | |
27 | class QRimage {\r | |
28 | \r | |
29 | //----------------------------------------------------------------------\r | |
30 | public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) \r | |
31 | {\r | |
32 | $image = self::image($frame, $pixelPerPoint, $outerFrame);\r | |
33 | \r | |
34 | if ($filename === false) {\r | |
35 | Header("Content-type: image/png");\r | |
36 | ImagePng($image);\r | |
37 | } else {\r | |
38 | if($saveandprint===TRUE){\r | |
39 | ImagePng($image, $filename);\r | |
40 | header("Content-type: image/png");\r | |
41 | ImagePng($image);\r | |
42 | }else{\r | |
43 | ImagePng($image, $filename);\r | |
44 | }\r | |
45 | }\r | |
46 | \r | |
47 | ImageDestroy($image);\r | |
48 | }\r | |
49 | \r | |
50 | //----------------------------------------------------------------------\r | |
51 | public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) \r | |
52 | {\r | |
53 | $image = self::image($frame, $pixelPerPoint, $outerFrame);\r | |
54 | \r | |
55 | if ($filename === false) {\r | |
56 | Header("Content-type: image/jpeg");\r | |
57 | ImageJpeg($image, null, $q);\r | |
58 | } else {\r | |
59 | ImageJpeg($image, $filename, $q); \r | |
60 | }\r | |
61 | \r | |
62 | ImageDestroy($image);\r | |
63 | }\r | |
64 | \r | |
65 | //----------------------------------------------------------------------\r | |
66 | private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) \r | |
67 | {\r | |
68 | $h = count($frame);\r | |
69 | $w = strlen($frame[0]);\r | |
70 | \r | |
71 | $imgW = $w + 2*$outerFrame;\r | |
72 | $imgH = $h + 2*$outerFrame;\r | |
73 | \r | |
74 | $base_image =ImageCreate($imgW, $imgH);\r | |
75 | \r | |
76 | $col[0] = ImageColorAllocate($base_image,255,255,255);\r | |
77 | $col[1] = ImageColorAllocate($base_image,0,0,0);\r | |
78 | \r | |
79 | imagefill($base_image, 0, 0, $col[0]);\r | |
80 | \r | |
81 | for($y=0; $y<$h; $y++) {\r | |
82 | for($x=0; $x<$w; $x++) {\r | |
83 | if ($frame[$y][$x] == '1') {\r | |
84 | ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); \r | |
85 | }\r | |
86 | }\r | |
87 | }\r | |
88 | \r | |
89 | $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);\r | |
90 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);\r | |
91 | ImageDestroy($base_image);\r | |
92 | \r | |
93 | return $target_image;\r | |
94 | }\r | |
95 | } |