Pridana podpora generovani a cteni carovych kodu
[mirrors/SokoMan.git] / lib / Barcode.class.php
diff --git a/lib/Barcode.class.php b/lib/Barcode.class.php
new file mode 100755 (executable)
index 0000000..7292825
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/*
+ * Barcode Class
+ * Copyright (C) 2011  Thomas Mudrunka
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+* Trida implementuje funkce pro praci s carovymi kody
+*
+* @package  Barcode
+* @author   Tomas Mudrunka
+*/
+class Barcode {
+       static function test() {
+               system('barcode -b test | convert - /dev/null', $ret);
+               if($ret == 0) {
+                       return true;
+               } else {
+                       trigger_error('Barcode-related features are disabled. Please install GNU Barcode and ImageMagick.');
+                       return false;
+               }
+       }
+
+       static function generate_barcode($string='EXAMPLE', $convert='png', $enctype='code128b') {
+               $string = escapeshellarg($string);
+               $enctype = escapeshellarg($enctype);
+               $convert = $convert ? " | convert -colorspace gray -background white - $convert:-" : '';
+               return shell_exec("barcode -e $enctype -E -b $string$convert");
+       }
+
+       static function cached_barcode($string='EXAMPLE', $convert='png', $enctype='code128b') {
+               $ext = $convert ? $convert : 'ps';
+               $filename=DIR_BARCODES."/$enctype-".urlencode($string).".$ext";
+               if(is_file($filename)) return file_get_contents($filename);
+               $barcode = self::generate_barcode($string,$convert,$enctype);
+               file_put_contents($filename,$barcode);
+               return $barcode;
+       }
+
+       static function download_barcode($string='EXAMPLE', $convert='png', $enctype='code128b') {
+               if(self::test()) header('Content-Type: image/png'); else die();
+               die(self::cached_barcode($string,$convert,$enctype));
+       }
+}
This page took 0.12611 seconds and 4 git commands to generate.