Пример #1
0
 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);
 }
Пример #2
0
 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);
 }