コード例 #1
0
 /**
  * Draws the barcode.
  *
  * @param resource $im
  */
 public function draw($im)
 {
     // The following code is exactly the same as EAN13. We just add a 0 in front of the code !
     $this->text = '0' . $this->text;
     // We will remove it at the end... don't worry
     parent::draw($im);
     // We remove the 0 in front, as we said :)
     $this->text = substr($this->text, 1);
 }
コード例 #2
0
ファイル: BCGisbn.barcode.php プロジェクト: rajarshc/Rooja
 /**
  * Check chars allowed.
  */
 protected function checkCharsAllowed()
 {
     $c = strlen($this->text);
     // Special case, if we have 10 digits, the last one can be X
     if ($c === 10) {
         if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') {
             throw new BCGParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.');
         }
         // Drop the last char
         $this->text = substr($this->text, 0, 9);
     }
     return parent::checkCharsAllowed();
 }
コード例 #3
0
ファイル: BarcodeGenerator13.php プロジェクト: jkevinp/bepco
 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();
 }
コード例 #4
0
 /**
  * Overloaded method for drawing special label
  *
  * @param resource $im
  */
 protected function drawText($im)
 {
     parent::drawText($im);
     if (strlen($this->isbn_created) > 0) {
         $pA = $this->getMaxSize();
         $pB = BCGBarcode1D::getMaxSize();
         $w = $pA[0] - $pB[0];
         if ($this->isbn_textfont instanceof BCGFont) {
             $textfont = clone $this->isbn_textfont;
             $textfont->setText($this->isbn_created);
             $xPosition = $w / 2 - $textfont->getWidth() / 2 + $this->offsetX * $this->scale;
             $yPosition = $this->offsetY * $this->scale - BCGBarcode1D::SIZE_SPACING_FONT;
             $textfont->draw($im, $this->colorFg->allocate($im), $xPosition, $yPosition);
         } elseif ($this->isbn_textfont !== 0) {
             $xPosition = $w / 2 - strlen($this->isbn_created) / 2 * imagefontwidth($this->isbn_textfont) + $this->offsetX * $this->scale;
             $yPosition = $this->offsetY * $this->scale - BCGBarcode1D::SIZE_SPACING_FONT - imagefontheight($this->isbn_textfont);
             imagestring($im, $this->isbn_textfont, $xPosition, $yPosition, $this->isbn_created, $this->colorFg->allocate($im));
         }
     }
 }
コード例 #5
0
// 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');
require_once 'class/BCGean13.barcode.php';
// Loading Font
$font = new BCGFontFile('./class/font/Arial.ttf', 10);
$barcode = str_pad($_GET['code'], 12, "0", STR_PAD_LEFT);
// 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 BCGean13();
    $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($barcode);
    // Text
} catch (Exception $exception) {
    $drawException = $exception;
}
コード例 #6
0
 function drawBars(&$im)
 {
     // Checksum
     $this->calculateChecksum();
     $temp_text = $this->text . $this->keys[$this->checksumValue];
     // Starting Code
     $this->drawChar($im, '000', true);
     // Draw Second Code
     $this->drawChar($im, $this->findCode($temp_text[1]), false);
     // Draw Manufacturer Code
     for ($i = 0; $i < 5; $i++) {
         $this->drawChar($im, BCGean13::inverse($this->findCode($temp_text[$i + 2]), $this->codeParity[(int) $temp_text[0]][$i]), false);
     }
     // Draw Center Guard Bar
     $this->drawChar($im, '00000', false);
     // Draw Product Code
     for ($i = 7; $i < 13; $i++) {
         $this->drawChar($im, $this->findCode($temp_text[$i]), true);
     }
     // Draw Right Guard Bar
     $this->drawChar($im, '000', true);
 }
コード例 #7
0
ファイル: BCGisbn.barcode.php プロジェクト: marsa1985/kazabiz
 /**
  * Overloaded method for drawing special label.
  *
  * @param resource $im
  */
 protected function drawText($im)
 {
     parent::drawText($im);
     if (strlen($this->isbn_created) > 0) {
         $pA = $this->getMaxSize();
         $pB = BCGBarcode1D::getMaxSize();
         $w = $pA[0] - $pB[0];
         if ($this->getISBNFont() instanceof BCGFont) {
             $textfont = clone $this->getISBNFont();
             $textfont->setText($this->isbn_created);
             $xPosition = max(0, $w / 2 - $textfont->getWidth() / 2 + ($this->offsetX - $this->ean13offsetX) * $this->scale);
             $yPosition = $this->offsetY * $this->scale - BCGBarcode1D::SIZE_SPACING_FONT + 1;
             // +1 for anti-aliasing
             $textfont->draw($im, $this->colorFg->allocate($im), $xPosition, $yPosition);
         } elseif ($this->getISBNFont() !== 0) {
             $xPosition = $w / 2 - strlen($this->isbn_created) / 2 * imagefontwidth($this->getISBNFont()) + ($this->offsetX - $this->ean13offsetX) * $this->scale;
             $yPosition = $this->offsetY * $this->scale - BCGBarcode1D::SIZE_SPACING_FONT - imagefontheight($this->getISBNFont());
             imagestring($im, $this->getISBNFont(), $xPosition, $yPosition, $this->isbn_created, $this->colorFg->allocate($im));
         }
     }
 }