. */ /** * 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 - -crop 0x60+0+30\\! -background none -flatten $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'); header('Cache-Control: max-age=604800, public'); //1week caching } else die(); error_reporting(0); //TODO: enable errors again die(self::cached_barcode($string,$convert,$enctype)); } }