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); }
require_once $ruta . '/extensions/barcodegen/class/BCGFontFile.php'; require_once $ruta . '/extensions/barcodegen/class/BCGColor.php'; require_once $ruta . '/extensions/barcodegen/class/BCGDrawing.php'; require_once $ruta . '/extensions/barcodegen/class/BCGcode128.barcode.php'; // Loading Font $font = new BCGFontFile($ruta . '/extensions/barcodegen/font/Arial.ttf', 8); // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); // Barcode Part $code = new BCGcode128(); $code->setScale(2); $code->setThickness(30); //tamaño en vertical pixel $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->setStart(NULL); $code->setTilde(true); $code->parse($cabFact['ClaveAcceso']); $code->clearLabels(); //Elmina el TItulo de la LIbreria // Drawing Part //$drawing = new BCGDrawing(Yii::app()->theme->baseUrl.'/images/plantilla/filename.png', $color_white); $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); $drawing->setFilename(Yii::app()->params['seaBarra'] . $cabFact['IdentificacionComprador'] . '.png'); header('Content-Type: image/png'); //header('Content-Type: text/html; charset=utf-8'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
require_once $ruta . '/extensions/barcodegen/class/BCGFontFile.php'; require_once $ruta . '/extensions/barcodegen/class/BCGColor.php'; require_once $ruta . '/extensions/barcodegen/class/BCGDrawing.php'; require_once $ruta . '/extensions/barcodegen/class/BCGcode128.barcode.php'; // Loading Font $font = new BCGFontFile($ruta . '/extensions/barcodegen/font/Arial.ttf', 8); // The arguments are R, G, B for color. $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); // Barcode Part $code = new BCGcode128(); $code->setScale(2); $code->setThickness(30); //tamaño en vertical pixel $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->setStart(NULL); $code->setTilde(true); $code->parse($ClaveAcceso); $code->clearLabels(); //Elmina el TItulo de la LIbreria // Drawing Part //$drawing = new BCGDrawing(Yii::app()->theme->baseUrl.'/images/plantilla/filename.png', $color_white); $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); $drawing->setFilename(Yii::app()->params['seaBarra'] . $Identificacion . '.png'); header('Content-Type: image/png'); //header('Content-Type: text/html; charset=utf-8'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
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; }
$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); $drawing->draw(); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); $count++; } header('Content-Type: image/png');