/** * Constructor */ public function __construct() { parent::__construct(); // We just put parenthesis around special characters. $this->keys[self::EXTENDED_1] = '($)'; $this->keys[self::EXTENDED_2] = '(/)'; $this->keys[self::EXTENDED_3] = '(+)'; $this->keys[self::EXTENDED_4] = '(%)'; $this->errorText = ''; }
/** * Constructor */ function BCGcode39extended() { // public BCGcode39::BCGcode39(); // We just put parenthesis around special characters. $this->keys[$this->EXTENDED_1] = '($)'; $this->keys[$this->EXTENDED_2] = '(/)'; $this->keys[$this->EXTENDED_3] = '(+)'; $this->keys[$this->EXTENDED_4] = '(%)'; $this->errorText = ''; }
/** * 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 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); }
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); }
// Including all required classes require_once 'class/BCGFontFile.php'; require_once 'class/BCGColor.php'; require_once 'class/BCGDrawing.php'; // Including the barcode technology require_once 'class/BCGcode39.barcode.php'; // Loading Font $font = new BCGFontFile('./font/Arial.ttf', 8); // Don't forget to sanitize user inputs $text = isset($_GET['text']) ? $_GET['text'] : 'HELLO'; // 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($text); // Text } catch (Exception $exception) { $drawException = $exception; }
/** * Validates the input. */ protected function validate() { $c = count($this->data); if ($c === 0) { throw new BCGParseException('code39extended', 'No data has been entered.'); } parent::validate(); }
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); }
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; }
// Color of spaces $code->setFont($font); // Font (or 0) $code->parse($employee['code']); $code->clearLabels(); $drawing = new BCGDrawing('', $colorBack); $drawing->setFilename('./barcodes/' . $employee['name'] . '.png'); $drawing->setBarcode($code); $drawing->draw(); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); } die; $emp_codes = array('11506025', '19810002', '11404011', '11105007', '10907001', '19411001', '11302006'); $count = 0; foreach ($emp_codes as $number) { $code = new BCGcode39(); // 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->setFont($font); // Font (or 0) $code->parse($number); $drawing = new BCGDrawing('', $colorBack); $drawing->setFilename($count . '.png'); $drawing->setBarcode($code);
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); }
<?php require 'class/BCGFontFile.php'; require 'class/BCGColor.php'; require 'class/BCGDrawing.php'; require 'class/BCGcode39.barcode.php'; $font = new BCGFontFile('class/font/Arial.ttf', 18); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); // Barcode Part $code = new BCGcode39(); $code->setScale(2); $code->setThickness(30); $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->setChecksum(false); $code->parse('A123'); // Drawing Part $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
/** * 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); }
<?php require_once 'class/BCGColor.php'; require_once 'class/BCGDrawing.php'; require_once 'class/BCGcode39.barcode.php'; $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(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);