/** * Returns the maximal size of a barcode * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); $array = str_split($this->text, 1); $textlength = (array_sum($array) + count($array)) * $this->scale; return array($p[0] + $textlength, $p[1]); }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('othercode', 'No data has been entered.'); } parent::validate(); }
/** * Returns the maximal size of a barcode. * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); $textlength = 12 * strlen($this->text) * $this->scale; $startlength = 3 * $this->scale; $checksumlength = $this->checksum * 12 * $this->scale; $endlength = 4 * $this->scale; return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]); }
/** * Returns the maximal size of a barcode. * * @param int $w * @param int $h * @return int[] */ public function getDimension($w, $h) { $textlength = 12 * strlen($this->text); $startlength = 3; $checksumlength = $this->checksum * 12; $endlength = 4; $w += $startlength + $textlength + $checksumlength + $endlength; $h += $this->thickness; return parent::getDimension($w, $h); }
/** * Returns the maximal size of a barcode * * @return int */ public function getMaxSize() { $p = parent::getMaxSize(); $c = strlen($this->text); $startlength = 6 * $this->scale; $textlength = $c * 5 * 6 * $this->scale; $checksumlength = 5 * 6 * $this->scale; $endlength = 6 * $this->scale; // We remove the white on the right $removelength = -3 * $this->scale; return array($p[0] + $startlength + $textlength + $checksumlength + $endlength + $removelength, $p[1]); }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('othercode', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new BCGParseException('othercode', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } parent::validate(); }
/** * Returns the maximal size of a barcode * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); $w = 0; $c = strlen($this->text); for ($i = 0; $i < $c; $i++) { $index = $this->findIndex($this->text[$i]); if ($index !== false) { $w += 8; $w += substr_count($this->code[$index], '1'); } } return array($p[0] + $w * $this->scale, $p[1]); }
/** * Overloaded method for drawing special label * * @param resource $im */ protected function drawText($im) { if ($this->label !== BCGBarcode1D::AUTO_LABEL && $this->label !== '') { $pA = $this->getMaxSize(); $pB = BCGBarcode1D::getMaxSize(); $w = $pA[0] - $pB[0]; if ($this->textfont instanceof BCGFont) { $textfont = clone $this->textfont; $textfont->setText($this->label); $xPosition = $w / 2 - $textfont->getWidth() / 2 + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $textfont->getHeight() - $textfont->getUnderBaseline() + BCGBarcode1D::SIZE_SPACING_FONT + $this->offsetY * $this->scale; $text_color = $this->colorFg->allocate($im); $textfont->draw($im, $text_color, $xPosition, $yPosition); } elseif ($this->textfont !== 0) { $xPosition = $w / 2 - strlen($this->label) * imagefontwidth($this->textfont) / 2 + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $this->offsetY * $this->scale + BCGBarcode1D::SIZE_SPACING_FONT; $text_color = $this->colorFg->allocate($im); imagestring($im, $this->textfont, $xPosition, $yPosition, $this->label, $text_color); } } }
/** * Returns the maximal size of a barcode * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); $w = 0; $c = strlen($this->text); for ($i = 0; $i < $c; $i++) { $index = $this->findIndex($this->text[$i]); if ($index !== false) { $w += 6; $w += substr_count($this->code[$index], '1'); } } $startlength = 8 * $this->scale; $textlength = $w * $this->scale; // We take the max length possible for checksums (it is 7 or 8...) $checksumlength = 8 * $this->scale; if ($c >= 10) { $checksumlength += 8 * $this->scale; } $endlength = 7 * $this->scale; return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]); }
/** * Validates the input. */ protected function validate() { $c = count($this->data); if ($c === 0) { throw new BCGParseException('code128', 'No data has been entered.'); } parent::validate(); }
/** * Returns the maximal size of a barcode * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); // Contains start + text + checksum + stop $textlength = count($this->data) * 11 * $this->scale; $endlength = 2 * $this->scale; // + final bar return array($p[0] + $textlength + $endlength, $p[1]); }
/** * Returns the maximal size of a barcode * * @return int[] */ function getMaxSize() { $p = BCGBarcode1D::getMaxSize(); $textlength = 7 * strlen($this->text) * $this->scale; $startlength = 4 * $this->scale; $checksumlength = 0; if ($this->checksum === true) { $checksumlength = 7 * $this->scale; } $endlength = 4 * $this->scale; return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]); }
/** * Returns the maximal size of a barcode * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); $c = strlen($this->text); $startlength = 8 * $this->scale; $textlength = $c * 14 * $this->scale; $checksumlength = 0; if ($c % 2 !== 0) { $checksumlength = 14 * $this->scale; } $endlength = 7 * $this->scale; return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]); }
/** * Draws the label under the barcode * * @param resource $im */ function drawText(&$im) { // protected $label = $this->getLabel(); if (!empty($label)) { $pA = $this->getMaxSize(); $pB = BCGBarcode1D::getMaxSize(); $w = $pA[0] - $pB[0]; if (is_a($this->textfont, 'BCGFont')) { $textfont = $this->textfont; // clone $textfont->setText($label); $xPosition = $w / 2 - $textfont->getWidth() / 2 + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $textfont->getHeight() - $textfont->getUnderBaseline() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale; $textfont->draw($im, $this->colorFg->allocate($im), $xPosition, $yPosition); } elseif ($this->textfont !== 0) { $xPosition = $w / 2 - strlen($label) / 2 * imagefontwidth($this->textfont) + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale; imagestring($im, $this->textfont, $xPosition, $yPosition, $label, $this->colorFg->allocate($im)); } } }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('ean13', 'No data has been entered.'); } $this->checkCharsAllowed(); $this->checkCorrectLength(); parent::validate(); }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('postnet', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new BCGParseException('postnet', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must contain 5, 9 or 11 chars if ($c !== 5 && $c !== 9 && $c !== 11) { throw new BCGParseException('postnet', 'Must contain 5, 9, or 11 characters.'); } parent::validate(); }
/** * 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)); } } }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('ean8', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new BCGParseException('ean8', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // If we have 8 chars just flush the last one if ($c === 8) { $this->text = substr($this->text, 0, 7); } elseif ($c !== 7) { throw new BCGParseException('ean8', 'Must contain 7 digits, the 8th digit is automatically added.'); } parent::validate(); }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('upce', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new BCGParseException('upce', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must contain 11 chars // Must contain 6 chars (if starting with upce directly) // First Chars must be 0 or 1 if ($c !== 11 && $c !== 6) { throw new BCGParseException('upce', 'You must provide a UPC-A (11 characters) or a UPC-E (6 characters).'); } elseif ($this->text[0] !== '0' && $this->text[0] !== '1' && $c !== 6) { throw new BCGParseException('upce', 'UPC-A must start with 0 or 1 to be converted to UPC-E.'); } // Convert part $this->upce = ''; if ($c !== 6) { // Checking if UPC-A is convertible $temp1 = substr($this->text, 3, 3); if ($temp1 === '000' || $temp1 === '100' || $temp1 === '200') { // manufacturer code ends with 100, 200 or 300 if (substr($this->text, 6, 2) === '00') { // Product must start with 00 $this->upce = substr($this->text, 1, 2) . substr($this->text, 8, 3) . substr($this->text, 3, 1); } } elseif (substr($this->text, 4, 2) === '00') { // manufacturer code ends with 00 if (substr($this->text, 6, 3) === '000') { // Product must start with 000 $this->upce = substr($this->text, 1, 3) . substr($this->text, 9, 2) . '3'; } } elseif (substr($this->text, 5, 1) === '0') { // manufacturer code ends with 0 if (substr($this->text, 6, 4) === '0000') { // Product must start with 0000 $this->upce = substr($this->text, 1, 4) . substr($this->text, 10, 1) . '4'; } } else { // No zero leading at manufacturer code $temp2 = intval(substr($this->text, 10, 1)); if (substr($this->text, 6, 4) === '0000' && $temp2 >= 5 && $temp2 <= 9) { // Product must start with 0000 and must end by 5, 6, 7, 8 or 9 $this->upce = substr($this->text, 1, 5) . substr($this->text, 10, 1); } } } else { $this->upce = $this->text; } if ($this->upce === '') { throw new BCGParseException('upce', 'Your UPC-A can\'t be converted to UPC-E.'); } if ($c === 6) { $upca = ''; // We convert UPC-E to UPC-A to find the checksum if ($this->text[5] === '0' || $this->text[5] === '1' || $this->text[5] === '2') { $upca = substr($this->text, 0, 2) . $this->text[5] . '0000' . substr($this->text, 2, 3); } elseif ($this->text[5] === '3') { $upca = substr($this->text, 0, 3) . '00000' . substr($this->text, 3, 2); } elseif ($this->text[5] === '4') { $upca = substr($this->text, 0, 4) . '00000' . $this->text[4]; } else { $upca = substr($this->text, 0, 5) . '0000' . $this->text[5]; } $this->text = '0' . $upca; } parent::validate(); }
/** * Overloaded method for drawing special label * * @param resource $im */ function drawText(&$im) { if ($this->label !== $this->AUTO_LABEL) { BCGBarcode1D::drawText($im); } elseif ($this->label !== '') { $temp_text = $this->text . $this->keys[$this->checksumValue]; if (is_a($this->textfont, 'BCGFont')) { $code1 = 0; $code2 = 0; $this->textfont->setText($temp_text); $this->drawExtendedBars($im, $this->textfont->getHeight(), $code1, $code2); // We need to separate the text, one on the left and one on the right, one starting and one ending $text0 = substr($temp_text, 1, 1); $text1 = substr($temp_text, 2, 5); $text2 = substr($temp_text, 7, 5); $text3 = substr($temp_text, 12, 1); $font0 = $this->textfont; // clone $font1 = $this->textfont; // clone $font2 = $this->textfont; // clone $font3 = $this->textfont; // clone $font0->setText($text0); $font1->setText($text1); $font2->setText($text2); $font3->setText($text3); $xPosition0 = $this->offsetX * $this->scale - $font0->getWidth() - 4; // -4 is just for beauty; $xPosition3 = $this->offsetX * $this->scale + $this->positionX * $this->scale + 2; $yPosition0 = $this->thickness * $this->scale + $font0->getHeight() / 2 + $this->offsetY * $this->scale; $xPosition1 = ($this->scale * 36 - $font1->getWidth()) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale; $xPosition2 = ($this->scale * 37 - $font2->getWidth()) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $this->textfont->getHeight() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale; $text_color = $this->colorFg->allocate($im); $font0->draw($im, $text_color, $xPosition0, $yPosition0); $font1->draw($im, $text_color, $xPosition1, $yPosition); $font2->draw($im, $text_color, $xPosition2, $yPosition); $font3->draw($im, $text_color, $xPosition3, $yPosition0); } elseif ($this->textfont !== 0) { $code1 = 0; $code2 = 0; $this->drawExtendedBars($im, 9, $code1, $code2); $xPosition0 = $this->offsetX * $this->scale - imagefontwidth($this->textfont); $xPosition3 = $this->offsetX * $this->scale + $this->positionX * $this->scale + 2; $yPosition0 = $this->thickness * $this->scale - imagefontheight($this->textfont) / 2 + $this->offsetY * $this->scale; $xPosition1 = ($this->scale * 36 - imagefontwidth($this->textfont) * 5) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale; $xPosition2 = ($this->scale * 37 - imagefontwidth($this->textfont) * 5) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $this->offsetY * $this->scale; $text_color = $this->colorFg->allocate($im); imagechar($im, $this->textfont, $xPosition0, $yPosition0, $temp_text[1], $text_color); imagestring($im, $this->textfont, $xPosition1, $yPosition, substr($temp_text, 2, 5), $text_color); imagestring($im, $this->textfont, $xPosition2, $yPosition, substr($temp_text, 7, 5), $text_color); imagechar($im, $this->textfont, $xPosition3, $yPosition0, $temp_text[12], $text_color); } } }
/** * Validates the input. */ protected function validate() { // Tracking must have been entered if ($this->barcodeIdentifier === null || $this->serviceTypeIdentifier === null || $this->mailerIdentifier === null || $this->serialNumber === null) { throw new BCGParseException('intelligentmail', 'The tracking code must be set before calling the parse method.'); } // Checking if all chars are allowed $match = array(); if (preg_match('/[^0-9]/', $this->text, $match)) { throw new BCGParseException('intelligentmail', 'The character \'' . $match[0] . '\' is not allowed.'); } // Must contain 0, 5, 9 or 11 chars $c = strlen($this->text); if ($c !== 0 && $c !== 5 && $c !== 9 && $c !== 11) { throw new BCGParseException('intelligentmail', 'Must contain 0, 5, 9, or 11 characters.'); } parent::validate(); }
/** * Returns the maximal size of a barcode * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); $startlength = 9 * $this->scale; $textlength = 9 * count($this->data) * $this->scale; $checksumlength = 2 * 9 * $this->scale; $endlength = 9 * $this->scale + $this->scale; // + final bar return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]); }
/** * Overloaded method for drawing special label * * @param resource $im */ protected function drawText($im) { if ($this->label !== BCGBarcode1D::AUTO_LABEL) { parent::drawText($im); } elseif ($this->label !== '') { $temp_text = $this->text . $this->keys[$this->checksumValue]; if ($this->textfont instanceof BCGFont) { $code1 = 0; $code2 = 0; $this->textfont->setText($temp_text); $this->drawExtendedBars($im, $this->textfont->getHeight(), $code1, $code2); // We need to separate the text, one on the left and one on the right and one starting $text0 = substr($temp_text, 0, 1); $text1 = substr($temp_text, 1, 6); $text2 = substr($temp_text, 7, 6); $font0 = clone $this->textfont; $font1 = clone $this->textfont; $font2 = clone $this->textfont; $font0->setText($text0); $font1->setText($text1); $font2->setText($text2); $xPosition0 = $this->offsetX * $this->scale - $font0->getWidth() - 4; // -4 is just for beauty $yPosition0 = $this->thickness * $this->scale + $font0->getHeight() / 2 + $this->offsetY * $this->scale; $xPosition1 = ($this->scale * 44 - $font1->getWidth()) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale; $xPosition2 = ($this->scale * 44 - $font1->getWidth()) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $this->textfont->getHeight() + self::SIZE_SPACING_FONT + $this->offsetY * $this->scale; $text_color = $this->colorFg->allocate($im); $font0->draw($im, $text_color, $xPosition0, $yPosition0); $font1->draw($im, $text_color, $xPosition1, $yPosition); $font2->draw($im, $text_color, $xPosition2, $yPosition); } elseif ($this->textfont !== 0) { $code1 = 0; $code2 = 0; $this->drawExtendedBars($im, 9, $code1, $code2); $startPosition = 10; $xPosition0 = $this->offsetX * $this->scale - imagefontwidth($this->textfont); $yPosition0 = $this->thickness * $this->scale - imagefontheight($this->textfont) / 2 + $this->offsetY * $this->scale; $xPosition1 = ($this->scale * 44 - imagefontwidth($this->textfont) * 6) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale; $xPosition2 = ($this->scale * 44 - imagefontwidth($this->textfont) * 6) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + 1 * $this->scale + $this->offsetY * $this->scale; $text_color = $this->colorFg->allocate($im); imagechar($im, $this->textfont, $xPosition0, $yPosition0, $temp_text[0], $text_color); imagestring($im, $this->textfont, $xPosition1, $yPosition, substr($temp_text, 1, 6), $text_color); imagestring($im, $this->textfont, $xPosition2, $yPosition, substr($temp_text, 7, 6), $text_color); } } }
/** * Returns the maximal size of a barcode. * * @return int[] */ public function getMaxSize() { $p = BCGBarcode1D::getMaxSize(); $textlength = 13 * count($this->data) * $this->scale; $startlength = 13 * $this->scale; $checksumlength = 0; if ($this->checksum === true) { $checksumlength = 13 * $this->scale; } $endlength = 13 * $this->scale; return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]); }
/** * Overloaded method for drawing special label. * * @param resource $im */ protected function drawText($im) { if ($this->label !== BCGBarcode1D::AUTO_LABEL) { parent::drawText($im); } elseif ($this->label !== '') { $temp_text = $this->text . $this->keys[$this->checksumValue]; if ($this->textfont instanceof BCGFont) { $code1 = 0; $code2 = 0; $this->textfont->setText($temp_text); $this->drawExtendedBars($im, $this->textfont->getHeight(), $code1, $code2); // We need to separate the text, one on the left and one on the right $text1 = substr($temp_text, 0, 4); $text2 = substr($temp_text, 4, 4); $font1 = clone $this->textfont; $font2 = clone $this->textfont; $font1->setText($text1); $font2->setText($text2); // The $this->res offset is to center without thinking of the white space in the guard $xPosition1 = ($this->scale * 30 - $font1->getWidth()) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale; $xPosition2 = ($this->scale * 30 - $font2->getWidth()) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + $this->textfont->getHeight() + BCGBarcode1D::SIZE_SPACING_FONT + $this->offsetY * $this->scale; $text_color = $this->colorFg->allocate($im); $font1->draw($im, $text_color, $xPosition1, $yPosition); $font2->draw($im, $text_color, $xPosition2, $yPosition); } elseif ($this->textfont !== 0) { $code1 = 0; $code2 = 0; $this->drawExtendedBars($im, 9, $code1, $code2); $xPosition1 = ($this->scale * 30 - imagefontwidth($this->textfont) * 4) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale; $xPosition2 = ($this->scale * 30 - imagefontwidth($this->textfont) * 4) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale; $yPosition = $this->thickness * $this->scale + 1 * $this->scale + $this->offsetY * $this->scale; $text_color = $this->colorFg->allocate($im); imagestring($im, $this->textfont, $xPosition1, $yPosition, substr($temp_text, 0, 4), $text_color); imagestring($im, $this->textfont, $xPosition2, $yPosition, substr($temp_text, 4, 4), $text_color); } } }
/** * Returns the maximal size of a barcode * * @return int[] */ public function getMaxSize() { $p = parent::getMaxSize(); $textlength = 13 * strlen($this->text) * $this->scale; $startlength = 13 * $this->scale; $checksumlength = 0; if ($this->checksum === true) { $checksumlength = 13 * $this->scale; } $endlength = 13 * $this->scale; return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]); }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('codabar', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new BCGParseException('codabar', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must start by A, B, C or D if ($c == 0 || $this->text[0] !== 'A' && $this->text[0] !== 'B' && $this->text[0] !== 'C' && $this->text[0] !== 'D') { throw new BCGParseException('codabar', 'The text must start by the character A, B, C, or D.'); } // Must end by A, B, C or D $c2 = $c - 1; if ($c2 === 0 || $this->text[$c2] !== 'A' && $this->text[$c2] !== 'B' && $this->text[$c2] !== 'C' && $this->text[$c2] !== 'D') { throw new BCGParseException('codabar', 'The text must end by the character A, B, C, or D.'); } parent::validate(); }
/** * Overloaded method for drawing special label. * * @param resource $im */ protected function drawText($im) { $label = $this->getLabel(); if (!empty($label)) { $pA = $this->getMaxSize(); $pB = BCGBarcode1D::getMaxSize(); $w = $pA[0] - $pB[0]; if ($this->textfont instanceof BCGFont) { $textfont = clone $this->textfont; $textfont->setText($label); $xPosition = $w / 2 - $textfont->getWidth() / 2 + $this->offsetX * $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->textfont !== 0) { $xPosition = $w / 2 - strlen($label) / 2 * imagefontwidth($this->textfont) + $this->offsetX * $this->scale; $yPosition = $this->offsetY * $this->scale - BCGBarcode1D::SIZE_SPACING_FONT - imagefontheight($this->textfont); imagestring($im, $this->textfont, $xPosition, $yPosition, $label, $this->colorFg->allocate($im)); } } }
/** * Validates the input. */ protected function validate() { $c = strlen($this->text); if ($c === 0) { throw new BCGParseException('s25', 'No data has been entered.'); } // Checking if all chars are allowed for ($i = 0; $i < $c; $i++) { if (array_search($this->text[$i], $this->keys) === false) { throw new BCGParseException('s25', 'The character \'' . $this->text[$i] . '\' is not allowed.'); } } // Must be even if ($c % 2 !== 0 && $this->checksum === false) { throw new BCGParseException('s25', 's25 must contain an even amount of digits if checksum is false.'); } elseif ($c % 2 === 0 && $this->checksum === true) { throw new BCGParseException('s25', 's25 must contain an odd amount of digits if checksum is true.'); } parent::validate(); }
/** * Returns the maximal size of a barcode. * * @param int $w * @param int $h * @return int[] */ public function getDimension($w, $h) { $textlength = 13 * count($this->data); $startlength = 13; $checksumlength = 0; if ($this->checksum === true) { $checksumlength = 13; } $endlength = 13; $w += $startlength + $textlength + $checksumlength + $endlength; $h += $this->thickness; return BCGBarcode1D::getDimension($w, $h); }