Oprava prevodu z PS do PNG pro novejsi verzi GNU barcode
[mirrors/SokoMan.git] / lib / Barcode.class.php
CommitLineData
81ab8aef
TM
1<?php
2/*
3 * Barcode Class
4 * Copyright (C) 2011 Thomas Mudrunka
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20/**
21* Trida implementuje funkce pro praci s carovymi kody
22*
23* @package Barcode
24* @author Tomas Mudrunka
25*/
26class Barcode {
27 static function test() {
28 system('barcode -b test | convert - /dev/null', $ret);
29 if($ret == 0) {
30 return true;
31 } else {
32 trigger_error('Barcode-related features are disabled. Please install GNU Barcode and ImageMagick.');
33 return false;
34 }
35 }
36
37 static function generate_barcode($string='EXAMPLE', $convert='png', $enctype='code128b') {
38 $string = escapeshellarg($string);
39 $enctype = escapeshellarg($enctype);
b0f54db3 40 $convert = $convert ? " | convert - -crop 0x60+0+30\\! -background none -flatten $convert:-" : '';
81ab8aef
TM
41 return shell_exec("barcode -e $enctype -E -b $string$convert");
42 }
43
44 static function cached_barcode($string='EXAMPLE', $convert='png', $enctype='code128b') {
45 $ext = $convert ? $convert : 'ps';
46 $filename=DIR_BARCODES."/$enctype-".urlencode($string).".$ext";
47 if(is_file($filename)) return file_get_contents($filename);
48 $barcode = self::generate_barcode($string,$convert,$enctype);
49 file_put_contents($filename,$barcode);
50 return $barcode;
51 }
52
53 static function download_barcode($string='EXAMPLE', $convert='png', $enctype='code128b') {
c6712080
TM
54 if(self::test()) {
55 header('Content-Type: image/png');
56 header('Cache-Control: max-age=604800, public'); //1week caching
57 } else die();
51d3b8cf 58 error_reporting(0); //TODO: enable errors again
81ab8aef
TM
59 die(self::cached_barcode($string,$convert,$enctype));
60 }
61}
This page took 0.187017 seconds and 4 git commands to generate.