]>
git.wh0rd.org - tt-rss.git/blob - lib/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)
32 $image = self
::image($frame, $pixelPerPoint, $outerFrame);
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)
69 $w = strlen($frame[0]);
71 $imgW = $w +
2*$outerFrame;
72 $imgH = $h +
2*$outerFrame;
74 $base_image =ImageCreate($imgW, $imgH);
76 $col[0] = ImageColorAllocate($base_image,255,255,255);
77 $col[1] = ImageColorAllocate($base_image,0,0,0);
79 imagefill($base_image, 0, 0, $col[0]);
81 for($y=0; $y<$h; $y++
) {
82 for($x=0; $x<$w; $x++
) {
83 if ($frame[$y][$x] == '1') {
84 ImageSetPixel($base_image,$x+
$outerFrame,$y+
$outerFrame,$col[1]);
89 $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
90 ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
91 ImageDestroy($base_image);