/** * 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; }