public function code128Action($text = null) { $text = $text ? $text : '000-000-000'; if ($this->format !== 'png') { return $this->redirect("scan-code/code-128/{$text}.png", true); } $labelStyle = $this->form->labelStyle->getString(); if (!in_array($labelStyle, ['normal', 'none'])) { $labelStyle = 'normal'; } $fileName = md5($text . $labelStyle) . '.png'; $path = "{$this->cachePath}/{$fileName}"; if (file_exists($path) && time() - filemtime($path) < $this->recacheTime) { return file_get_contents($path); } $font = new \BCGFontFile(\Lvs\ROOT_PATH . '/fonts/Arial.ttf', 14); $black = new \BCGColor(0, 0, 0); $white = new \BCGColor(255, 255, 255); $ex = null; try { $code = new \BCGcode128(); $code->setScale(3); $code->setThickness(30); $code->setForegroundColor($black); $code->setBackgroundColor($white); $code->setFont($font); if ($labelStyle === 'none') { $code->setLabel(null); } $code->parse($text); } catch (\Exception $e) { $ex = $e; } $img = new \BCGDrawing($path, $white); if ($ex) { $img->drawException($ex); } else { $img->setBarcode($code); $img->draw(); } $img->finish(\BCGDrawing::IMG_FORMAT_PNG); if (!file_exists($path)) { $img->setFilename(null); $img->draw(); $img->finish(\BCGDrawing::IMG_FORMAT_PNG); return ''; } return file_get_contents($path); }
/** * 获取条形码服务 * 用法:http://s.dachuwang.com/barcode/get?text=2015081923456&thickness=70&scale=1&source=F * @param string text 条码内容,必须 * @param string source 条码类型,用于区分不同场景的扫码,必须 * @param number thickness 条码高度(20-90),默认为50 * @param number scale 条码大小(1-4), 默认为2 * @author yuanxiaolin@dachuwang.com */ public function get() { try { $this->load->model('DataModel', 'datamodel'); $params = $this->datamodel->barcode_params(); $colorFront = new BCGColor(0, 0, 0); $colorBack = new BCGColor(255, 255, 255); //$font = new BCGFontFile(BARCODE_DIR.'/font/Arial.ttf', 14); $code = new BCGcode128(); $code->setScale($params['scale']); // 条码显示大小:1-4,默认为2 $code->setThickness($params['thickness']); // 条码显示高度:20-90,默认50 $code->setForegroundColor($colorFront); // 条码颜色为黑色 $code->setBackgroundColor($colorBack); // 条码背景为白色 //$code->setFont($font); $code->parse($params['text']); // 条码内容 $drawing = new BCGDrawing('', $colorBack); $drawing->setBarcode($code); $drawing->draw(); //header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); } catch (Exception $e) { echo $e->getMessage(); } }
function index() { $text = rawurldecode($this->input->get('text')); $barcode = rawurldecode($this->input->get('barcode')); $scale = $this->input->get('scale') ? $this->input->get('scale') : 1; $thickness = $this->input->get('thickness') ? $this->input->get('thickness') : 30; $font = new BCGFontFile(APPPATH . 'libraries/barcode/font/Arial.ttf', 10); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); // Barcode Part $code = new BCGcode128(); $code->setScale($scale); $code->setThickness($thickness); $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->setLabel($text); $code->parse($barcode); // Drawing Part $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
public function codebarAction() { require_once 'Codebar/BCGFontFile.php'; require_once 'Codebar/BCGColor.php'; require_once 'Codebar/BCGDrawing.php'; $this->getResponse()->setHeader('Content-type', 'image/png'); // The arguments are R, G, and B for color. $colorFont = new BCGColor(0, 0, 0); $colorBack = new BCGColor(255, 255, 255); $code = $this->codeBarFactory($this->getRequest()->get('CODE')); // Or another class name from the manual $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($colorFont); // Color of bars $code->setBackgroundColor($colorBack); // Color of spaces $code->parse($this->getRequest()->get('BAR')); // Text $drawing = new BCGDrawing('', $colorBack); $drawing->setBarcode($code); $drawing->draw(); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
public function codebar() { $tipo_code = $_GET['tipo_code']; $bar = $_GET['bar']; require_once 'Codebar/BCGFontFile.php'; require_once 'Codebar/BCGColor.php'; require_once 'Codebar/BCGDrawing.php'; // The arguments are R, G, and B for color. $colorFont = new BCGColor(0, 0, 0); $colorBack = new BCGColor(255, 255, 255); $code = $this->codeBarFactory($tipo_code); // Or another class name from the manual $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($colorFont); // Color of bars $code->setBackgroundColor($colorBack); // Color of spaces $code->parse($bar); // Text $drawing = new BCGDrawing('', $colorBack); $drawing->setBarcode($code); $drawing->draw(); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
function draw($text = "1111111111111") { $_GET = array('code' => "BCGcode128", 'filetype' => "PNG", 'dpi' => 72, 'scale' => 1, 'rotation' => 0, 'font_family' => "Arial.ttf", 'font_size' => 8, 'text' => $text, 'thickness' => 30); $filetypes = array('PNG' => BCGDrawing::IMG_FORMAT_PNG, 'JPEG' => BCGDrawing::IMG_FORMAT_JPEG, 'GIF' => BCGDrawing::IMG_FORMAT_GIF); $drawException = null; try { $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $code_generated = new BCGcode128(); if (function_exists('baseCustomSetup')) { baseCustomSetup($code_generated, $_GET); } if (function_exists('customSetup')) { customSetup($code_generated, $_GET); } $code_generated->setScale(max(1, min(4, $_GET['scale']))); $code_generated->setBackgroundColor($color_white); $code_generated->setForegroundColor($color_black); if ($_GET['text'] !== '') { $text = convertText($_GET['text']); $code_generated->parse($text); } } catch (Exception $exception) { $drawException = $exception; } $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code_generated); $drawing->setRotationAngle($_GET['rotation']); $drawing->setDPI($_GET['dpi'] === 'NULL' ? null : max(72, min(300, intval($_GET['dpi'])))); $drawing->draw(); } switch ($_GET['filetype']) { case 'PNG': header('Content-Type: image/png'); break; case 'JPEG': header('Content-Type: image/jpeg'); break; case 'GIF': header('Content-Type: image/gif'); break; } $drawing->finish($filetypes[$_GET['filetype']]); }
/** * Created by PhpStorm. * User: wenzi * Date: 11/26/13 * Time: 3:51 PM */ function generate_barcode($text, $file_name) { // Including all required classes require_once 'barcode/class/BCGFontFile.php'; require_once 'barcode/class/BCGColor.php'; require_once 'barcode/class/BCGDrawing.php'; // Including the barcode technology require_once 'barcode/class/BCGcode39.barcode.php'; // Loading Font $CURRENT_TEMPLATE_URL = dirname(Yii::app()->basePath) . Yii::app()->params['THEME_BASE_URL']; $font = new BCGFontFile($CURRENT_TEMPLATE_URL . '/fonts/helvetica_neue_thin.ttf', 18); // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode39(); $code->setScale(2); // Resolution $code->setThickness(40); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($text); // Text $code->clearLabels(); } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing($file_name, $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
function generateBarcode() { require 'components/com_enmasse/helpers/barcodegen/class/BCGFont.php'; require 'components/com_enmasse/helpers/barcodegen/class/BCGColor.php'; require 'components/com_enmasse/helpers/barcodegen/class/BCGDrawing.php'; include 'components/com_enmasse/helpers/barcodegen/class/BCGcode128.barcode.php'; $num = $_GET['num']; // Loading Font $font = new BCGFont('components/com_enmasse/helpers/barcodegen/class/font/Arial.ttf', 13); // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode128(); //$code->setScale(1.5); // Resolution $code->setThickness(40); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($num); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Header that says it is an image (remove it if you save the barcode to a file) header('Content-Type: image/png'); // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); die; }
public function create($text = '', $filename = '') { if (!$text) { return false; } $font = new BCGFontFile(CUR_CONF_PATH . 'lib/barcodegen/font/Arial.ttf', $this->font); $text = $text ? $text : 'NO INPUTS'; $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode128(); $code->setScale(2); // Resolution $code->setThickness(60); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($text); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing($filename, $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Header that says it is an image (remove it if you save the barcode to a file) /* header('Content-Type: image/png'); header('Content-Disposition: inline; filename="barcode.png"'); */ $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); return true; }
function on_barcode($number = '') { if (empty($number)) { die_json(array('error_code' => 10041, '条形码不能为空')); } include_once LIBS_DIR . 'barcode/class/BCGFontFile.php'; include_once LIBS_DIR . 'barcode/class/BCGColor.php'; include_once LIBS_DIR . 'barcode/class/BCGDrawing.php'; include_once LIBS_DIR . 'barcode/class/BCGcode39.barcode.php'; // 加载字体大小 $font = new BCGFontFile(LIBS_DIR . 'barcode/font/Arial.ttf', 18); //颜色条形码 $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode39(); $code->setScale(2); $code->setThickness(30); // 条形码的厚度 $code->setForegroundColor($color_black); // 条形码颜色 $code->setBackgroundColor($color_white); // 空白间隙颜色 $code->setFont($font); // $code->parse($number); // 条形码需要的数据内容 } catch (Exception $exception) { $drawException = $exception; } //根据以上条件绘制条形码 $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // 生成PNG格式的图片 header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
function output($key, $type, $path) { $barcode = $key ? $key : 'HELLO'; // Loading Font $file = public_path() . '\\font\\Arial.ttf'; if (file_exists($file)) { $font = new BCGFont($file, 6); } else { die('Font does not exist <Br/>' . $file); } // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $code = new BCGean13(); $code->setScale(1); // Resolution $code->setThickness(15); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($key); // Text // $filename = $key . $code->getCheckSum() . "." . $type; $fullpath = $path . "\\" . $filename; //$code->setDPI(72); /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing($fullpath, $color_white); $drawing->setBarcode($code); $drawing->draw(); // Header that says it is an image (remove it if you save the barcode to a file) //header('Content-Type: image/png'); // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); return $key . $code->getCheckSum(); }
public function __construct($code_text) { // Loading Font $font = new BCGFontFile('../barcode/font/Arial.ttf', 0); // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode39(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($code_text); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing('../img/barcodes/' . $code_text . '.png', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
public function run() { /* $className = 'BCGcodabar'; $baseClassFile = 'BCGBarcode1D.php'; $codeVersion = '5.0.2';*/ $color_black = new \BCGColor(0, 0, 0); $color_white = new \BCGColor(255, 255, 255); $filetypes = array('PNG' => \BCGDrawing::IMG_FORMAT_PNG, 'JPEG' => \BCGDrawing::IMG_FORMAT_JPEG, 'GIF' => \BCGDrawing::IMG_FORMAT_GIF); $code_generated = new \BCGcode128(); $this->baseCustomSetup($code_generated); $code_generated->setScale(max(1, min(4, 4))); $code_generated->setBackgroundColor($color_white); $code_generated->setForegroundColor($color_black); $code_generated->parse($this->message); $drawing = new \BCGDrawing('', $color_white); $drawing->setBarcode($code_generated); $drawing->setRotationAngle(0); $drawing->setDPI(72); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish($filetypes['PNG']); return "Hello!"; }
/** * Printing a barcode 39 * * @Route /new/example/barcode * */ public function barcodeAction() { $colorfg = new \BCGColor(0, 0, 0); $colorbg = new \BCGColor(255, 255, 255); // Barcode Part $code = new \BCGcode39(); $code->setScale(3); $code->setColor($colorfg, $colorbg); $code->parse('EHD2345543453'); // Drawing Part $drawing = new \BCGDrawing('', $colorbg); $drawing->setBarcode($code); $drawing->draw(); $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG); $this->app->contentType(\Raptor\Raptor::PNG); }
public static function uniqueBarcode($mac = NULL, $min = 11111111111, $max = 99999999999) { if ($mac == NULL) { $mac = Util::getCONNECTED_MAC(NULL); } if ($mac == NULL) { return Proximus::barcode(); } $identifier = "" . mt_rand($min, $max); try { $res = Proximus::onetimeUniqueUser("./uniqueBarcode.txt", $mac, $identifier); if ($res != NULL || isset($res[2])) { $identifier = trim($res[2]); } } catch (Exception $e) { $identifier = trim($identifier); } Logger::barcode('UPC-A', $identifier, $mac); $font = new BCGFontFile('/home/proximus/bin/php/barcode/font/Arial.ttf', 18); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGupca(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($identifier); // Text } catch (Exception $exception) { $drawException = $exception; } $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
public function getBarcode($filename) { $filePath = 'Public/File/barcode/' . $filename . ".png"; if (file_exists($filePath)) { return; } // 引用class文件夹对应的类 require_once __ROOT__ . '/ThinkPHP/Library/Vendor/barcode/class/BCGFontFile.php'; require_once __ROOT__ . '/ThinkPHP/Library/Vendor/barcode/class/BCGColor.php'; require_once __ROOT__ . '/ThinkPHP/Library/Vendor/barcode/class/BCGDrawing.php'; require_once __ROOT__ . '/ThinkPHP/Library/Vendor/barcode/class/BCGcode39.barcode.php'; // 加载字体大小 $font = new \BCGFontFile('ThinkPHP/Library/Vendor/barcode/font/Arial.ttf', 18); //颜色条形码 $color_black = new \BCGColor(0, 0, 0); $color_white = new \BCGColor(255, 255, 255); $drawException = null; try { $code = new \BCGcode39(); $code->setScale(1.5); $code->setThickness(13); // 条形码的厚度 $code->setForegroundColor($color_black); // 条形码颜色 $code->setBackgroundColor($color_white); // 空白间隙颜色 $code->setFont($font); // $code->parse($filename); // 条形码需要的数据内容 } catch (Exception $exception) { $drawException = $exception; } //根据以上条件绘制条形码 $drawing = new \BCGDrawing('Public/File/barcode/' . $filename . ".png", $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // 生成PNG格式的图片 header('Content-Type: image/png'); $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG); }
public function create($texto = '') { if ($texto) { // Variables $f_name = $this->font_name; $f_size = $this->font_size; $escala = $this->barcode_escala; $grosor = $this->barcode_grosor; $tipo = $this->barcode_img_tipo; // Cargar fuente $font = new BCGFontFile($f_name, $f_size); // Definción de colores $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { switch ($this->barcode_encode) { case 'code39': $code = new BCGcode39(); break; case 'code93': $code = new BCGcode93(); break; case 'code128': $code = new BCGcode128(); break; case 'ean8': $code = new BCGean8(); break; case 'ean13': $code = new BCGean13(); break; default: $code = new BCGcode128(); break; } // $code = new BCGcode128(); $code->setScale($escala); // Resolucion $code->setThickness($grosor); // grosor $code->setForegroundColor($color_black); // Color de barras $code->setBackgroundColor($color_white); // Color de espacios $code->setFont($font); // Fuente (or 0) $code->parse($texto); // Texto } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing($this->archivo, $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Identificación de formato y Crear imagen al vuelo switch ($tipo) { case 'wbmp': // $ext = 'wbmp'; // $mime = 'image/vnd.wap.wbmp'; // header('Content-Type: '.$mime); // header('Content-Disposition: inline; filename="barcode.'.$ext.'"'); $drawing->finish(BCGDrawing::IMG_FORMAT_WBMP); break; case 'png': // $ext = 'png'; // $mime = 'image/png'; // header('Content-Type: '.$mime); // header('Content-Disposition: inline; filename="barcode.'.$ext.'"'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); break; case 'gif': // $ext = 'gif'; // $mime = 'image/gif'; // header('Content-Type: '.$mime); // header('Content-Disposition: inline; filename="barcode.'.$ext.'"'); $drawing->finish(BCGDrawing::IMG_FORMAT_GIF); break; case 'jpg': // $ext = 'jpg'; // $mime = 'image/jpeg'; // header('Content-Type: '.$mime); // header('Content-Disposition: inline; filename="barcode.'.$ext.'"'); $drawing->finish(BCGDrawing::IMG_FORMAT_JPEG); break; default: return false; break; } return $this->archivo; } else { return false; } }
protected function insertTrack(&$page, $shipment) { $tracks = array(); if ($shipment) { $tracks = $shipment->getAllTracks(); } if (count($tracks)) { $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $font = $this->_setFontBold($page, 15); foreach ($tracks as $track) { $CarrierCode = $track->getCarrierCode(); if ($CarrierCode != 'custom') { $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode); $carrierTitle = $carrier->getConfigData('title'); } else { $carrierTitle = Mage::helper('sales')->__('Custom Value'); } $truncatedTitle = strtoupper(substr($track->getTitle(), 0, 45) . (strlen($track->getTitle()) > 45 ? '...' : '')); $feed = $this->getAlignCenter($truncatedTitle, 20, 290, $font, 15); $page->drawText($truncatedTitle, $feed, 210, 'UTF-8'); // Convert to barcode $drawException = null; try { $code = new BCGcode128(); $code->setScale(3); // Resolution $code->setThickness(40); // Thickness $code->setForegroundColor($this->color_black); // Color of bars $code->setBackgroundColor($this->color_white); // Color of spaces $code->setFont($this->barcodeFont); // Font (or 0) $code->parse($track->getNumber()); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $barcodeFile = tempnam(Mage::getConfig()->getOptions()->getTmpDir(), 'BarCode_Ship'); $drawing = new BCGDrawing($barcodeFile, $this->color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); // RENAME FILE $pngFile = $barcodeFile . ".png"; rename($barcodeFile, $pngFile); $image = Zend_Pdf_Image::imageWithPath($pngFile); $page->drawImage($image, 60, 75, 260, 175); unlink($pngFile); } } // Now do the order Shipping Number // Convert to barcode $drawException = null; try { $code = new BCGcode128(); $code->setScale(3); // Resolution $code->setThickness(40); // Thickness $code->setForegroundColor($this->color_black); // Color of bars $code->setBackgroundColor($this->color_white); // Color of spaces $code->setFont($this->barcodeFont); // Font (or 0) $code->parse($shipment->getIncrementId()); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $barcodeFile = tempnam(Mage::getConfig()->getOptions()->getTmpDir(), 'BarCode_Ship'); $drawing = new BCGDrawing($barcodeFile, $this->color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); // RENAME FILE $pngFile = $barcodeFile . ".png"; rename($barcodeFile, $pngFile); $image = Zend_Pdf_Image::imageWithPath($pngFile); $page->drawImage($image, 350, 65, 550, 155); unlink($pngFile); }
public static function imprimirSelecionados() { ini_set("display_errors", "off"); $cracha = new Cracha(); $crachas = $cracha->listar('evento = \'br30\' AND id IN (' . implode(",", $_POST['idsCrachas']) . ')', 'nome'); $posicaoInicio = $_POST['posicao']; $totalPaginas = ceil(count($crachas) / 10); for ($i = 1; $i < $posicaoInicio; $i++) { array_unshift($crachas, array()); } $divisaoCrachas = array(); for ($i = 1; $i <= $totalPaginas; $i++) { $divisaoCrachas[$i] = array_slice($crachas, ($i - 1) * 10, 10); } $divisaoCrachasTemp = array(); foreach ($divisaoCrachas as $indice => $unDivisaoCrachas) { for ($i = 1; $i <= 5; $i++) { $divisaoCrachasTemp[$indice][$i] = !empty($unDivisaoCrachas) ? array_slice($unDivisaoCrachas, ($i - 1) * 2, 2) : array('teste1', 'teste2'); } } $divisaoCrachas = $divisaoCrachasTemp; $codigosDeBarras = array(); foreach ($crachas as $cracha) { $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $font = new BCGFontFile(__DIR__ . '/../components/barcodegen/font/Arial.ttf', 18); $code = new BCGcode39(); // Or another class name from the manual $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse(str_pad($cracha->fk_participante, 4, "0", STR_PAD_LEFT)); // Text // $code->clearLabels(); ob_start(); $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); $codigosDeBarras[$cracha->id] = ob_get_contents(); ob_end_clean(); ob_start(); } header('Content-Type: text/html;'); self::$header = ''; self::$topo = ''; self::$menu = ''; self::$corpo = "imprimirSelecionados"; self::$footer = ''; self::$variaveis = array('divisaoCrachas' => $divisaoCrachas, 'codigosDeBarras' => $codigosDeBarras, 'posicaoInicio' => $posicaoInicio); self::renderizar(self::$viewController); }
function barcode($code) { if (!isset($_GET['filetype'])) { $_GET['filetype'] = 'PNG'; } if (!isset($_GET['dpi'])) { $_GET['dpi'] = '72'; } if (!isset($_GET['thickness'])) { $_GET['thickness'] = '30'; } if (!isset($_GET['scale'])) { $_GET['scale'] = '1'; } if (!isset($_GET['rotation'])) { $_GET['rotation'] = '0'; } if (!isset($_GET['font_family'])) { $_GET['font_family'] = 'Arial.ttf'; } if (!isset($_GET['font_size'])) { $_GET['font_size'] = '8'; } if (!isset($_GET['setChecksum'])) { $_GET['setChecksum'] = '0'; } if (!isset($_GET['code'])) { $_GET['code'] = 'BCGcode39'; } $_GET['text'] = $code; $requiredKeys = array('code', 'filetype', 'dpi', 'thickness', 'scale', 'rotation', 'font_family', 'font_size', 'text'); $possibleCodes = array('BCGcodabar', 'BCGcode11', 'BCGcode39', 'BCGcode39extended', 'BCGcode93', 'BCGcode128', 'BCGean8', 'BCGean13', 'BCGgs1128', 'BCGi25', 'BCGisbn', 'BCGmsi', 'BCGs25', 'BCGupca', 'BCGupce', 'BCGupcext2', 'BCGupcext5', 'BCGothercode', 'BCGpostnet', 'BCGintelligentmail'); // Check if everything is present in the request foreach ($requiredKeys as $key) { if (!isset($_GET[$key])) { showError(); } } // Check if the code is valid if (!in_array($_GET['code'], $possibleCodes)) { showError(); } $class_dir = 'class'; require_once $class_dir . DIRECTORY_SEPARATOR . 'BCGColor.php'; require_once $class_dir . DIRECTORY_SEPARATOR . 'BCGBarcode.php'; require_once $class_dir . DIRECTORY_SEPARATOR . 'BCGDrawing.php'; require_once $class_dir . DIRECTORY_SEPARATOR . 'BCGFontFile.php'; if (!(include_once $class_dir . DIRECTORY_SEPARATOR . $_GET['code'] . '.barcode.php')) { showError(); } $barcodeSupports = array('setChecksum' => array('BCGcode39', 'BCGcode39extended', 'BCGi25', 'BCGs25', 'BCGmsi'), 'setStart' => array('BCGcode128', 'BCGgs1128'), 'barcodeIdentifier' => array('BCGintelligentmail'), 'setLabel' => array('BCGothercode')); $filetypes = array('PNG' => BCGDrawing::IMG_FORMAT_PNG, 'JPEG' => BCGDrawing::IMG_FORMAT_JPEG, 'GIF' => BCGDrawing::IMG_FORMAT_GIF); $drawException = null; try { $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $font = 0; if ($_GET['font_family'] !== '0' && intval($_GET['font_size']) >= 1) { $font = new BCGFontFile(APPPATH . '/helpers/' . $class_dir . '/font/' . $_GET['font_family'], intval($_GET['font_size'])); } $code_generated = new $_GET['code'](); // Since image.php supports all barcode, we must check here // Which one support which option foreach ($barcodeSupports as $option => $barcodeNames) { if (isset($_GET[$option])) { if (in_array($_GET['code'], $barcodeNames)) { $value = $_GET[$option]; switch ($value) { case 'true': $value = true; break; case 'false': $value = false; break; case 'NULL': $value = null; break; default: if (is_numeric($value)) { // We accept only integer... $value = intval($value); } } switch ($option) { case 'setChecksum': case 'setStart': case 'setLabel': $code_generated->{$option}($value); break; case 'barcodeIdentifier': // Make sure we have all we need if (!isset($_GET['serviceType']) || !isset($_GET['mailerIdentifier']) || !isset($_GET['serialNumber'])) { break; } $code_generated->setTrackingCode(intval($_GET['barcodeIdentifier']), intval($_GET['serviceType']), intval($_GET['mailerIdentifier']), intval($_GET['serialNumber'])); break; } } } } $code_generated->setThickness($_GET['thickness']); $code_generated->setScale($_GET['scale']); $code_generated->setBackgroundColor($color_white); $code_generated->setForegroundColor($color_black); $code_generated->setFont($font); $code_generated->parse($_GET['text']); } catch (Exception $exception) { $drawException = $exception; } $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code_generated); $drawing->setRotationAngle($_GET['rotation']); $drawing->setDPI($_GET['dpi'] === 'NULL' ? null : intval($_GET['dpi'])); $drawing->draw(); } switch ($_GET['filetype']) { case 'PNG': header('Content-Type: image/png'); break; case 'JPEG': header('Content-Type: image/jpeg'); break; case 'GIF': header('Content-Type: image/gif'); break; } $drawing->finish($filetypes[$_GET['filetype']]); }
protected function insertOrderBarCode(&$page, $order) { // Convert to barcode $drawException = null; try { $code = new BCGcode128(); $code->setScale(2); // Resolution $code->setThickness(40); // Thickness $code->setForegroundColor($this->color_black); // Color of bars $code->setBackgroundColor($this->color_white); // Color of spaces $code->setFont($this->barcodeFont); // Font (or 0) $code->parse($order->getRealOrderId()); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $barcodeFile = tempnam(Mage::getConfig()->getOptions()->getTmpDir(), 'BarCode_Ship'); $drawing = new BCGDrawing($barcodeFile, $this->color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); // RENAME FILE $pngFile = $barcodeFile . ".png"; rename($barcodeFile, $pngFile); $image = Zend_Pdf_Image::imageWithPath($pngFile); $page->drawImage($image, 418, 752, 568, 820); unlink($pngFile); }
function drawBarcode($code, $scale_size, $text, $force_create_new = false, $returnAsHTML = true) { //CHECK IF EXIST $code_lc = strtolower($code); $code_uc = strtoupper($code); //Image Type to use $type = 1; if ($type === 1) { $file_ext = '.png'; } elseif ($type === 2) { $file_ext = '.jpg'; } elseif ($type === 3) { $file_ext = '.gif'; } $filepath = DIR_FS_BARCODES . $code_uc . '/'; $filename = $filepath . $text . '-' . $scale_size . $file_ext; if (!file_exists($filename) || $force_create_new) { $class_dir = 'barcodegen/'; $codebar = 'BCG' . $code_lc; if (!class_exists('BCGColor')) { use_class($class_dir . '/BCGColor'); } if (!class_exists('BCGBarcode')) { use_class($class_dir . '/BCGBarcode'); } if (!class_exists('BCGDrawing')) { use_class($class_dir . '/BCGDrawing'); } if (!class_exists('BCGFont')) { use_class($class_dir . '/BCGFont'); } if (!class_exists($codebar)) { use_class($class_dir . $codebar . '.barcode'); } switch ($scale_size) { case 'S': $font_size = 8; $thickness = 35; $scale = 1; break; case 'M': if ($codebar == 'BCGean13') { $font_size = 12; $thickness = 35; $scale = 2; } else { $font_size = 10; $thickness = 50; $scale = 1; } break; case 'L': $font_size = 12; $thickness = 65; $scale = 2; break; case 'AMVDBOX': $font_size = 0; $thickness = 50; $scale = 1; break; case 'AMVDPO': $font_size = 0; $thickness = 25; $scale = 2; break; } //Set Font $font = 0; if ($font_size > 0) { $font_file = DIR_WS_IMAGES . 'fonts/Arial.ttf'; if (file_exists($font_file)) { $font = new BCGFont($font_file, $font_size); } } //Set Colors $color_bg = new BCGColor(255, 255, 255); $color_fg = new BCGColor(0, 0, 0); //Set Code $code_generated = new $codebar(); // if use checksum for code39 // if($codebar=='BCGcode39') $code_generated->setChecksum(true); // code128 always use 128C as start if ($codebar == 'BCGcode128') { $code_generated->setStart('C'); } // other code always use label 'Other' if ($codebar == 'BCGothercode') { $code_generated->setLabel('Other'); } $code_generated->setThickness($thickness); $code_generated->setScale($scale); $code_generated->setBackgroundColor($color_bg); $code_generated->setForegroundColor($color_fg); $code_generated->setFont($font); $code_generated->parse($text); //Draw image if (!file_exists($filepath) || !is_dir($filepath)) { mkdir($filepath, 0750); } $drawing = new BCGDrawing($filename, $color_bg); $drawing->setBarcode($code_generated); $drawing->draw(); $drawing->finish($type); } $img_result = $code_uc . '/' . basename($filename); if ($returnAsHTML) { $img_result = '<img src="/' . DIR_WS_BARCODES . $img_result . '" alt="' . $text . '" />'; } return $img_result; }
/** * 条形码 */ public function barcode() { //获取code $code = $this->_GSCode(); //加载基础类库 require_once VENDOR_PATH . 'Barcodegen/class/BCGColor.php'; require_once VENDOR_PATH . 'Barcodegen/class/BCGBarcode.php'; require_once VENDOR_PATH . 'Barcodegen/class/BCGDrawing.php'; require_once VENDOR_PATH . 'Barcodegen/class/BCGFontFile.php'; //加载code128类库 require_once VENDOR_PATH . 'Barcodegen/class/BCGcode128.barcode.php'; //输出图片格式 $filetypes = array('PNG' => \BCGDrawing::IMG_FORMAT_PNG, 'JPEG' => \BCGDrawing::IMG_FORMAT_JPEG, 'GIF' => \BCGDrawing::IMG_FORMAT_GIF); //配置信息 $className = 'BCGcode128'; $codeconfig = array('filetype' => 'PNG', 'dpi' => '72', 'scale' => '3', 'rotation' => '0', 'font_family' => 'Arial.ttf', 'font_size' => '30', 'text' => $code, 'thickness' => '68', 'start' => 'A', 'code' => 'BCGcode128'); //画图 $drawException = null; try { $color_black = new \BCGColor(0, 0, 0); $color_white = new \BCGColor(255, 255, 255); $code_generated = new $className(); //设置样式 if (isset($codeconfig['thickness'])) { $code_generated->setThickness(max(9, min(90, intval($codeconfig['thickness'])))); } $font = 0; if ($codeconfig['font_family'] !== '0' && intval($codeconfig['font_size']) >= 1) { $font = new \BCGFontFile(VENDOR_PATH . 'Barcodegen/font/' . $codeconfig['font_family'], intval($codeconfig['font_size'])); } $code_generated->setFont($font); //编码方式A if (isset($codeconfig['start'])) { $code_generated->setStart($codeconfig['start'] === 'NULL' ? null : $codeconfig['start']); } $code_generated->setScale(max(1, min(4, $codeconfig['scale']))); $code_generated->setBackgroundColor($color_white); $code_generated->setForegroundColor($color_black); if ($codeconfig['text'] !== '') { $code = stripslashes($codeconfig['text']); if (function_exists('mb_convert_encoding')) { $code = mb_convert_encoding($code, 'ISO-8859-1', 'UTF-8'); } $code_generated->parse($code); } } catch (Exception $exception) { $drawException = $exception; } $drawing = new \BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code_generated); $drawing->setRotationAngle($codeconfig['rotation']); $drawing->setDPI($codeconfig['dpi'] === 'NULL' ? null : max(72, min(300, intval($codeconfig['dpi'])))); $drawing->draw(); } switch ($codeconfig['filetype']) { case 'PNG': header('Content-Type: image/png'); break; case 'JPEG': header('Content-Type: image/jpeg'); break; case 'GIF': header('Content-Type: image/gif'); break; } $drawing->finish($filetypes[$codeconfig['filetype']]); }
private function barcode2($sparepart_code, $barcode_type = 39, $scale = 6, $fontsize = 1, $thickness = 30, $dpi = 72) { // CREATE BARCODE GENERATOR // Including all required classes require_once APPPATH . 'libraries/barcodegen/BCGFontFile.php'; require_once APPPATH . 'libraries/barcodegen/BCGColor.php'; require_once APPPATH . 'libraries/barcodegen/BCGDrawing.php'; // Including the barcode technology // Ini bisa diganti-ganti mau yang 39, ato 128, dll, liat di folder barcodegen require_once APPPATH . 'libraries/barcodegen/BCGcode39.barcode.php'; // Loading Font // kalo mau ganti font, jangan lupa tambahin dulu ke folder font, baru loadnya di sini $font = new BCGFontFile(APPPATH . 'libraries/font/Arial.ttf', $fontsize); // Text apa yang mau dijadiin barcode, biasanya kode produk $text = $sparepart_code; // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode39(); // kalo pake yg code39, klo yg lain mesti disesuaikan $code->setScale($scale); // Resolution $code->setThickness($thickness); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($text); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setDPI($dpi); $drawing->setBarcode($code); $drawing->draw(); } // ini cuma labeling dari sisi aplikasi saya, penamaan file menjadi png barcode. $filename_img_barcode = $sparepart_code . '_' . $barcode_type . '.png'; // folder untuk menyimpan barcode $drawing->setFilename(FCPATH . 'uploads/bpjs/' . $sparepart_code . '.png'); // proses penyimpanan barcode hasil generate $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); return $filename_img_barcode; }
public function code128($kdnr, $vorname, $nachname, $gender) { $barcode = 'S' . $kdnr; $oo = 1; $pruefziffer = $this->pruefen($kdnr); $label = $kdnr . ' ' . $pruefziffer; $f1 = 'Arial.ttf'; $f2 = 8; $a1 = ''; $a2 = NULL; $a3 = ''; $t = 50; $r = 1; if ($f1 !== '0' && $f1 !== '-1' && intval($f2) >= 1) { //$font = new BCGFontFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('woehrl_stylecardantrag') . '/Classes/Barcode/Font'. $f1, intval($f2)); $font = new \BCGFontFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('woehrl_stylecardantrag') . 'Classes/Barcode/Font/' . $f1, intval($f2)); } else { $font = 0; } $color_black = new \BCGColor(0, 0, 0); $color_white = new \BCGColor(255, 255, 255); $codebar = 'BCGcode128'; $drawException = null; try { $code_generated = new $codebar(); if (isset($a1) && intval($a1) === 1) { $code_generated->setChecksum(true); } if (isset($a2) && !empty($a2)) { $code_generated->setStart($a2 === 'NULL' ? null : $a2); } if (isset($a3) && !empty($a3)) { $code_generated->setLabel($a3 === 'NULL' ? null : $a3); } $code_generated->setThickness($t); $code_generated->setScale($r); $code_generated->setBackgroundColor($color_white); $code_generated->setForegroundColor($color_black); $code_generated->setFont($font); $code_generated->setLabel($label); $code_generated->parse($barcode); } catch (Exception $exception) { $drawException = $exception; } $drawing = new \BCGDrawing('./uploads/tx_woehrlstylecardantrag/' . $kdnr . '.png', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code_generated); $drawing->setRotationAngle('0'); $drawing->setDPI('72'); $drawing->draw(); } $drawing->finish(intval($oo)); $image1 = imageCreateFromjpeg("./typo3conf/ext/woehrl_stylecardantrag/Resources/Public/Images/Woehrl-stylecard-Kundenkarte.jpg"); $image2 = imageCreateFromPNG('./uploads/tx_woehrlstylecardantrag/' . $kdnr . '.png'); imageCopy($image1, $image2, 28, 125, 0, 0, 123, 62); $color = ImageColorAllocate($image1, 255, 255, 255); $font_file = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('woehrl_stylecardantrag') . '/Classes/Barcode/Font/Arial.ttf'; if (strlen($vorname . ' ' . $nachname) < 24) { imagefttext($image1, 11, 0, 25, 70, $color, $font_file, $gender); imagefttext($image1, 11, 0, 25, 90, $color, $font_file, $vorname . ' ' . $nachname); } else { imagefttext($image1, 11, 0, 25, 70, $color, $font_file, $gender); imagefttext($image1, 11, 0, 25, 90, $color, $font_file, $nachname); } imagefttext($image1, 11, 0, 25, 110, $color, $font_file, $kdnr); if (imagejpeg($image1, './uploads/tx_woehrlstylecardantrag/stylecard_' . $kdnr . '.jpg', 100)) { return './uploads/tx_woehrlstylecardantrag/stylecard_' . $kdnr . '.jpg'; } }
function barcode($text) { #App::import('Vendor','BarcodeFont',array('file'=>'barcode'.DS.'BCGFontFile.php')); #App::import('Vendor','BarcodeColor',array('file'=>'barcode'.DS.'BCGColor.php')); App::import('Vendor', 'BarcodeDrawing', array('file' => 'barcode' . DS . 'BCGDrawing.php')); App::import('Vendor', 'Barcode128', array('file' => 'barcode' . DS . 'BCGcode128.barcode.php')); #pr(VENDORS.'barcode'.DS.'Arial.ttf'); #$font = new BCGFontFile(VENDORS.'barcode'.DS.'Arial.ttf', 18); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new BCGcode128(); $code->setScale(2); // Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces #$code->setFont($font); // Font (or 0) $code->parse($text); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Header that says it is an image (remove it if you save the barcode to a file) header('Content-Type: image/png'); header('Content-Disposition: inline; filename="barcode.png"'); // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }
// Resolution $code->setThickness(30); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $code->setFont($font); // Font (or 0) $code->parse($text); // Text } catch (Exception $exception) { $drawException = $exception; } /* Here is the list of the arguments 1 - Filename (empty : display on screen) 2 - Background color */ $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } // Header that says it is an image (remove it if you save the barcode to a file) header('Content-Type: image/png'); header('Content-Disposition: inline; filename="barcode.png"'); // Draw (or save) the image into PNG format. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
public function test() { $codebar = "BCGcode128"; //$_REQUEST['codebar']; $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawException = null; try { $code = new $codebar(); //实例化对应的编码格式 $code->setScale(2); // Resolution $code->setThickness(23); // Thickness $code->setForegroundColor($color_black); // Color of bars $code->setBackgroundColor($color_white); // Color of spaces $text = Req::args('code'); //条形码将要数据的内容 $code->parse($text); } catch (Exception $exception) { $drawException = $exception; } $drawing = new BCGDrawing('', $color_white); if ($drawException) { $drawing->drawException($drawException); } else { $drawing->setBarcode($code); $drawing->draw(); } header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); }