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);
 }
 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);
}
Beispiel #4
0
 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;
 }
Beispiel #5
0
 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;
 }
Beispiel #6
0
 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);
 }
Beispiel #7
0
 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);
 }
Beispiel #8
0
 /**
  * 条形码
  */
 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']]);
 }
 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);
 }
Beispiel #10
0
 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;
     }
 }
Beispiel #11
0
 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);
 }
Beispiel #12
0
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']]);
}
Beispiel #13
0
 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);
 }
Beispiel #14
0
 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);
 }
Beispiel #15
0
 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);
 }
Beispiel #16
0
 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;
 }
Beispiel #17
0
 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);
 }
Beispiel #18
0
    // 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 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';
     }
 }