/** * Constructor * * @param string $text * @param int $moduleSize */ public function __construct($text, $moduleSize = 2) { try { // Fill set A for ($i = 32; $i <= 95; $i++) { // chars SPACE - UNDERSPACE $this->setA[$i] = $i - 32; $this->charsA .= chr($i); $allowedChars[] = chr($i); } for ($i = 0; $i <= 31; $i++) { // chars NUL - US (Unit seperator) $this->setA[$i] = $i + 64; $this->charsA .= chr($i); $allowedChars[] = chr($i); } /* Fill set B * chars SPACE " " - "DEL" */ for ($i = 32; $i <= 127; $i++) { $this->setB[$i] = $i - 32; $this->charsB .= chr($i); $allowedChars[] = chr($i); } parent::__construct($text, $moduleSize, $allowedChars); $this->biteCode = $this->createBiteCode(); } catch (Exception $e) { throw $e; } }
/** * Constructor * * @param string $text * @param int $modulesize */ public function __construct($text, $moduleSize) { try { parent::__construct($text, $moduleSize, $this->allowedChars); $this->biteCode = $this->createBiteCode(); } catch (Exception $e) { throw $e; } }
/** * Constructor * * @param string $text * @param int $modulesize */ public function __construct($text, $moduleSize) { try { parent::__construct($text, $moduleSize, $this->allowedChars); if (strlen($this->text) % 2 != 0) { throw new Exception('The number of characters must be even', E_ODD_LENGTH); } $this->biteCode = $this->createBiteCode(); } catch (Exception $e) { throw $e; } }
/** * Draw * * @param bool $showText * @return image resource */ public function draw($showText = true) { $im = parent::draw(false); $margin = $this->margin * $this->moduleSize; $white = Imagecolorallocate($im, 255, 255, 255); $black = Imagecolorallocate($im, 0, 0, 0); if ($showText) { $im2 = ImageCreate($this->getBarcodeLen() * $this->moduleSize + 2 * $margin + $margin, $this->height + $this->fontSize + 2 * $margin); imagecopy($im2, $im, $margin, 0, 0, 0, $this->getBarcodeLen() * $this->moduleSize + 2 * $margin, $this->height + $this->fontSize + 2 * $margin); $charsA = $this->text[0]; for ($i = 1; $i <= strlen($this->text); $i++) { if ($i <= 6) { $charsB .= $this->text[$i]; } else { $charsC .= $this->text[$i]; } } $textWidth = ImageFontWidth($this->fontSize) * strlen($charsB); imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsB, $black); $textWidth = ImageFontWidth($this->fontSize) * strlen($charsC); imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize - $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsC, $black); } return $im2; }
/** * Draw * Add text into barcode * * @param bool $showText * @return image resource */ public function draw($showText = true) { $im = parent::draw(false); $margin = $this->margin * $this->moduleSize; $white = Imagecolorallocate($im, 255, 255, 255); $black = Imagecolorallocate($im, 0, 0, 0); if ($showText) { // Increase space between symbol 2x $im2 = ImageCreate($this->getBarcodeLen() * $this->moduleSize + 2 * $margin + $margin, $this->height + $this->fontSize + 2 * $margin); imagecopy($im2, $im, $margin, 0, 0, 0, $this->getBarcodeLen() * $this->moduleSize + 2 * $margin, $this->height + $this->fontSize + 2 * $margin); // Divide text into three parts and each insert to the diffrerent place $charsA = $this->text[0]; // first char for ($i = 1; $i <= strlen($this->text); $i++) { if ($i <= 6) { $charsB .= $this->text[$i]; } else { $charsC .= $this->text[$i]; } } // Insert A $textWidth = ImageFontWidth($this->fontSize) * strlen($charsA); imagestring($im2, $this->fontSize, $margin, $this->height - $this->fontSize / 2 + $margin, $charsA, $black); // Insert B $textWidth = ImageFontWidth($this->fontSize) * strlen($charsB); imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsB, $black); // Insert C $textWidth = ImageFontWidth($this->fontSize) * strlen($charsC); imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize - $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsC, $black); } return $im2; }