function BARCODE::_eanBarcode in Barcode 6
1 call to BARCODE::_eanBarcode()
File
- ./
barcode.inc.php, line 1652
Class
Code
function _eanBarcode($barnumber, $scale = 1, $file = "") {
$barnumber = $this
->_ean13CheckDigit($barnumber);
$bars = $this
->_eanEncode($barnumber);
if (empty($file)) {
header("Content-type: image/" . $this->_format);
}
if ($scale < 1) {
$scale = 2;
}
$total_y = (double) $scale * $this->_height;
if (!$space) {
$space = array(
'top' => 2 * $scale,
'bottom' => 2 * $scale,
'left' => 2 * $scale,
'right' => 2 * $scale,
);
}
/* count total width */
$xpos = 0;
$xpos = $scale * 114;
/* allocate the image */
$total_x = $xpos + $space['left'] + $space['right'];
$xpos = $space['left'] + $scale * 6;
$height = floor($total_y - $scale * 10);
$height2 = floor($total_y - $space['bottom']);
$im = @imagecreatetruecolor($total_x, $total_y);
$bg_color = @imagecolorallocate($im, $this->_bgcolor[0], $this->_bgcolor[1], $this->_bgcolor[2]);
@imagefilledrectangle($im, 0, 0, $total_x, $total_y, $bg_color);
$bar_color = @imagecolorallocate($im, $this->_color[0], $this->_color[1], $this->_color[2]);
for ($i = 0; $i < strlen($bars); $i++) {
$h = $height;
$val = strtoupper($bars[$i]);
if (preg_match("/[a-z]/i", $val)) {
$val = ord($val) - 65;
$h = $height2;
}
if ($this->_encode == "UPC-A" && ($i < 10 || $i > strlen($bars) - 13)) {
$h = $height2;
}
if ($val == 1) {
@imagefilledrectangle($im, $xpos, $space['top'], $xpos + $scale - 1, $h, $bar_color);
}
$xpos += $scale;
}
if ($this->_encode == "UPC-A") {
$str = substr($barnumber, 1, 1);
}
else {
$str = substr($barnumber, 0, 1);
}
@imagettftext($im, $scale * 6, 0, $space['left'], $height, $bar_color, $this->_font, $str);
if ($this->_encode == "UPC-A") {
$str = substr($barnumber, 2, 5);
}
else {
$str = substr($barnumber, 1, 6);
}
$x = $space['left'] + $scale * strlen($barnumber) + $scale * 6;
@imagettftext($im, $scale * 6, 0, $x, $height2, $bar_color, $this->_font, $str);
if ($this->_encode == "UPC-A") {
$str = substr($barnumber, 7, 5);
}
else {
$str = substr($barnumber, 7, 6);
}
$x = $space['left'] + $scale * strlen($bars) / 1.65 + $scale * 6;
@imagettftext($im, $scale * 6, 0, $x, $height2, $bar_color, $this->_font, $str);
if ($this->_encode == "UPC-A") {
$str = substr($barnumber, 12, 1);
$x = $total_x - $space['left'] - $scale * 6;
@imagettftext($im, $scale * 6, 0, $x, $height, $bar_color, $this->_font, $str);
}
if ($this->_format == "png") {
if (!empty($file)) {
@imagepng($im, $file . "." . $this->_format);
}
else {
@imagepng($im);
}
}
if ($this->_format == "gif") {
if (!empty($file)) {
@imagegif($im, $file . "." . $this->_format);
}
else {
@imagegif($im);
}
}
if ($this->_format == "jpg" || $this->_format == "jpeg") {
if (!empty($file)) {
@imagejpeg($im, $file . "." . $this->_format);
}
else {
@imagejpeg($im);
}
}
@imagedestroy($im);
}