Draws the barcode.

@param resource $im
430946
public function draw($im) {
        $this->drawBars($im);
        $this->drawText($im, 0, 0, $this->positionX, $this->thickness);

        if ($this->isDefaultEanLabelEnabled()) {
            $dimension = $this->labelCenter1->getDimension();
            $this->drawExtendedBars($im, $dimension[1] - 2);
        }
    }
648775
function WriteBarcode2($code, $x = '', $y = '', $size = 1, $height = 1, $bgcol = false, $col = false, $btype = 'IMB', $print_ratio = '', $k = 1)
	{
		if (empty($code)) {
			return;
		}

		$this->barcode = new Barcode();
		$arrcode = $this->barcode->getBarcodeArray($code, $btype, $print_ratio);

		if (empty($x)) {
			$x = $this->x;
		}

		if (empty($y)) {
			$y = $this->y;
		}

		$prevDrawColor = $this->DrawColor;
		$prevTextColor = $this->TextColor;
		$prevFillColor = $this->FillColor;
		$lw = $this->LineWidth;
		$this->SetLineWidth(0.01);
		$size /= $k; // in case resized in a table
		$xres = $arrcode['nom-X'] * $size;

		if ($btype === 'IMB' || $btype === 'RM4SCC' || $btype === 'KIX' || $btype === 'POSTNET' || $btype === 'PLANET') {
			$llm = $arrcode['quietL'] / $k; // Left Quiet margin
			$rlm = $arrcode['quietR'] / $k; // Right Quiet margin
			$tlm = $blm = $arrcode['quietTB'] / $k;
			$height = 1;  // Overrides
		} elseif (in_array($btype, ['C128A', 'C128B', 'C128C', 'EAN128A', 'EAN128B', 'EAN128C', 'C39', 'C39+', 'C39E', 'C39E+', 'S25', 'S25+', 'I25', 'I25+', 'I25B', 'I25B+', 'C93', 'MSI', 'MSI+', 'CODABAR', 'CODE11'])) {
			$llm = $arrcode['lightmL'] * $xres; // Left Quiet margin
			$rlm = $arrcode['lightmR'] * $xres; // Right Quiet margin
			$tlm = $blm = $arrcode['lightTB'] * $xres * $height;
		}

		$bcw = ($arrcode["maxw"] * $xres);
		$fbw = $bcw + $llm + $rlm;  // Full barcode width incl. light margins

		$bch = ($arrcode["nom-H"] * $size * $height);
		$fbh = $bch + $tlm + $blm;  // Full barcode height

		// PRINT border background color
		$xpos = $x;
		$ypos = $y;

		if ($col) {
			$this->SetDColor($col);
			$this->SetTColor($col);
		} else {
			$this->SetDColor($this->colorConverter->convert(0, $this->PDFAXwarnings));
			$this->SetTColor($this->colorConverter->convert(0, $this->PDFAXwarnings));
		}

		if ($bgcol) {
			$this->SetFColor($bgcol);
		} else {
			$this->SetFColor($this->colorConverter->convert(255, $this->PDFAXwarnings));
		}

		// PRINT BARS
		if ($col) {
			$this->SetFColor($col);
		} else {
			$this->SetFColor($this->colorConverter->convert(0, $this->PDFAXwarnings));
		}
		$xpos = $x + $llm;

		if ($arrcode !== false) {
			foreach ($arrcode["bcode"] as $v) {
				$bw = ($v["w"] * $xres);
				if ($v["t"]) {
					$ypos = $y + $tlm + ($bch * $v['p'] / $arrcode['maxh']);
					$this->Rect($xpos, $ypos, $bw, ($v['h'] * $bch / $arrcode['maxh']), 'F');
				}
				$xpos += $bw;
			}
		}

		// PRINT BEARER BARS
		if ($btype == 'I25B' || $btype == 'I25B+') {
			$this->Rect($x, $y, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
			$this->Rect($x, $y + $tlm + $bch, $fbw, ($arrcode['lightTB'] * $xres * $height), 'F');
		}

		// Restore **************
		$this->DrawColor = $prevDrawColor;
		$this->TextColor = $prevTextColor;
		$this->FillColor = $prevFillColor;
		$this->SetLineWidth($lw);
		$this->SetY($y);
	}
248200
public function draw($im) {
        $this->drawChar($im, $this->text, true);
        $this->drawText($im, 0, 0, $this->positionX, $this->thickness);
    }
1029623
protected function drawChar($im, $code, $startBar = true) {
        $c = strlen($code);
        for ($i = 0; $i < $c; $i++) {
            if ($code[$i] === '0') {
                $posY = $this->thickness - ($this->thickness / 2.5);
            } else {
                $posY = 0;
            }

            $this->drawFilledRectangle($im, $this->positionX, $posY, $this->positionX + 0.44, $this->thickness - 1, CINBarcode::COLOR_FG);
            $this->positionX += 3;
        }
    }
1315745
static public function validBirthday($iY, $iM, $iD)
    {
        $iDate = $iY . '-' . $iM . '-' . $iD;
        $rPattern = '/^(([0-9]{2})|(19[0-9]{2})|(20[0-9]{2}))-((0[1-9]{1})|(1[012]{1}))-((0[1-9]{1})|(1[0-9]{1})|(2[0-9]{1})|3[01]{1})$/';
        if (preg_match($rPattern, $iDate, $arr)) {
            return true;
        }
        return false;
    }
31565
private function generateBarcode($sString, $iWidth = null, $iHeight = null)
    {
        //  Prep the string
        $sString = strtoupper($sString);
        $sString = preg_replace('/[^A-Z0-9]/', '', $sString);

        // --------------------------------------------------------------------------

        if (empty($sString)) {

            $this->setError('String cannot be empty');
            return false;
        }

        // --------------------------------------------------------------------------

        /**
         * Create an oversized image first. We're going to generate the barcode with
         * the text centered then crop it to fit into an image of the requested size.
         */

        $_width  = 2000;
        $_height = 60;
        $rImg    = imagecreate($_width, $_height);

        //  Define the colours
        $rColorWhite = imagecolorallocate($rImg, 255, 255, 255);
        $rColorBlack = imagecolorallocate($rImg, 0, 0, 0);

        // --------------------------------------------------------------------------

        //  Write the barcode text, centered
        $iFontSize  = 36;
        $sFontPath  = $this->sFontPathBarcode;

        $aTextBox    = @imageTTFBbox($iFontSize, 0, $sFontPath, $sString);
        $iTextWidth  = abs($aTextBox[4] - $aTextBox[0]);
        $iTextHeight = abs($aTextBox[5] - $aTextBox[1]);
        $nTextX      = ($_width/2)-($iTextWidth/2)-2;
        $nTextY      = $iTextHeight;

        imagettftext($rImg, $iFontSize, 0, $nTextX, $nTextY, $rColorBlack, $sFontPath, $sString);

        $nBarcodeHeight = $iTextHeight;
        $nBarcodeWidth  = $iTextWidth;
        $nBarcodeTextX  = $nTextX;

        // --------------------------------------------------------------------------

        //  Write the number text, also centered
        $iFontSize = 14;
        $sFontPath = $this->sFontPathPlain;

        $aTextBox    = @imageTTFBbox($iFontSize, 0, $sFontPath, $sString);
        $iTextWidth  = abs($aTextBox[4] - $aTextBox[0]);
        $iTextHeight = abs($aTextBox[5] - $aTextBox[1]);
        $nTextX      = ($_width/2)-($iTextWidth/2)-2;
        $nTextY      = $nBarcodeHeight + $iTextHeight;

        /**
         * If the string contains a J or a Q then the positioning of the string
         * is skewed, adjust accordingly.
         */

        if (strpos($sString, 'J') == false && strpos($sString, 'Q') == false) {

            $nTextY += 5;
        }

        imagettftext($rImg, $iFontSize, 0, $nTextX, $nTextY, $rColorBlack, $sFontPath, $sString);

        // --------------------------------------------------------------------------

        /**
         * Crop image to fit barcode; it seems there's a PHP bug however - image crop
         * creates black lines when cropping: https://bugs.php.net/bug.php?id=67447
         */

        $aOptions           = array();
        $aOptions['height'] = $_height;
        $aOptions['width']  = max($nBarcodeWidth, $iTextWidth);
        $aOptions['y']      = 0;
        $aOptions['x']      = min($nBarcodeTextX, $nTextX);

        $rImgCropped = imagecrop($rImg, $aOptions);

        imagedestroy($rImg);

        // --------------------------------------------------------------------------

        /**
         * If a user defined width or height has been supplied then resize to those
         * dimensions.
         */

        if (!is_null($iWidth) || !is_null($iHeight)) {

            $iWidth      = is_null($iWidth) ? $aOptions['width']: $iWidth;
            $iHeight     = is_null($iHeight) ? $aOptions['height']: $iHeight;
            $_width      = min($iWidth, $aOptions['width']);
            $_height     = min($iHeight, $aOptions['height']);
            $rImgUser    = imagecreate($iWidth, $iHeight);
            $rColorWhite = imagecolorallocate($rImgUser, 255, 255, 255) ;

            imagecopyresampled(
                $rImgUser,
                $rImgCropped,
                0,
                0,
                0,
                0,
                $_width,
                $_height,
                $aOptions['width'],
                $aOptions['height']
            );

            return $rImgUser;

        } else {

            return $rImgCropped;
        }
    }
563028
private function createIm() {
        $w1 = imagesx($this->image1);
        $w2 = imagesx($this->image2);
        $h1 = imagesy($this->image1);
        $h2 = imagesy($this->image2);

        if ($this->position === self::POSITION_LEFT || $this->position === self::POSITION_RIGHT) {
            $w = $w1 + $w2 + $this->space;
            $h = max($h1, $h2);
        } else {
            $w = max($w1, $w2);
            $h = $h1 + $h2 + $this->space;
        }

        $this->im = imagecreatetruecolor($w, $h);
        imagefill($this->im, 0, 0, $this->background->allocate($this->im));

        // We start defining position of images
        if ($this->position === self::POSITION_TOP) {
            if ($w1 > $w2) {
                $posX1 = 0;
                $posX2 = $this->findPosition($w1, $w2, $this->alignment);
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posX1 = $this->findPosition($w1, $w2, $a);
                $posX2 = 0;
            }

            $posY2 = 0;
            $posY1 = $h2 + $this->space;
        } elseif ($this->position === self::POSITION_LEFT) {
            if ($w1 > $w2) {
                $posY1 = 0;
                $posY2 = $this->findPosition($h1, $h2, $this->alignment);
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posY2 = 0;
                $posY1 = $this->findPosition($h1, $h2, $a);
            }

            $posX2 = 0;
            $posX1 = $w2 + $this->space;
        } elseif ($this->position === self::POSITION_BOTTOM) {
            if ($w1 > $w2) {
                $posX2 = $this->findPosition($w1, $w2, $this->alignment);
                $posX1 = 0;
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posX2 = 0;
                $posX1 = $this->findPosition($w1, $w2, $a);
            }

            $posY1 = 0;
            $posY2 = $h1 + $this->space;
        } else { // defaults to RIGHT
            if ($w1 > $w2) {
                $posY2 = $this->findPosition($h1, $h2, $this->alignment);
                $posY1 = 0;
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posY2 = 0;
                $posY1 = $this->findPosition($h1, $h2, $a);
            }

            $posX1 = 0;
            $posX2 = $w1 + $this->space;
        }

        imagecopy($this->im, $this->image1, $posX1, $posY1, 0, 0, $w1, $h1);
        imagecopy($this->im, $this->image2, $posX2, $posY2, 0, 0, $w2, $h2);
    }
689810
protected function drawBarCode($baseline = 0.8, $height = 13)
    {
        $data = $this->data['barcode'];
        $wide = $baseline;
        $narrow = $baseline / 3;
        $map = [
            '00110',
            '10001',
            '01001',
            '11000',
            '00101',
            '10100',
            '01100',
            '00011',
            '10010',
            '01010'
        ];

        // If odd $data
        if ((strlen($data) % 2) != 0) {
            $data = '0' . $data;
        }
        // Generate bits to be draw
        $code = '0000'; // Leading value
        for ($i = 0, $l = strlen($data); $i < $l; $i += 2) {
            $code .= implode('', Utils\Utils::arrayInterpolate(
                $map[$data[$i]],
                $map[$data[$i + 1]]
            ));
        }
        $code .= '100'; // Trailing value

        // Draw
        $this->SetFillColor(0);
        $x = $this->GetX();
        $y = $this->GetY();
        $draw = true;
        foreach (str_split($code, 1) as $bit) {
            $width = ($bit == '0' ? $narrow : $wide);
            if ($draw) {
                $this->Rect($x, $y, $width, $height, 'F');
            }
            $x += $width;
            $draw = !$draw;
        }
        $this->Ln($height);
    }
1259130
protected function mbRenderImageByImagick($code, $encoding)
    {
        $backColor = $this->transparent ? new \ImagickPixel('transparent') : new \ImagickPixel(sprintf('#%06x', $this->backColor));
        $foreColor = new \ImagickPixel(sprintf('#%06x', $this->foreColor));

        $image = new \Imagick();
        $image->newImage($this->width, $this->height, $backColor);

        $draw = new \ImagickDraw();
        $draw->setFont($this->mbFontFile);
        $draw->setFontSize(30);
        $fontMetrics = $image->queryFontMetrics($draw, $code);

        $length = mb_strlen($code, $encoding);
        $w = (int)($fontMetrics['textWidth']) + $this->mbOffset * ($length - 1);
        $h = (int)($fontMetrics['textHeight']);
        $scale = min(($this->width - $this->padding * 2) / $w, ($this->height - $this->padding * 2) / $h);
        $x = 8;
        // font size and angle
        $fontSize = (int)(30 * $scale * 0.90);
        $angle = 0;
        // base line
        $yBottom = $this->height - $this->padding * 4;
        $yTop = (int)($h * $scale * 0.95) + $this->padding * 4;
        if ($yTop > $yBottom) {
            $yTop = $yBottom;
        }
        for ($i = 0; $i < $length; ++$i) {
            $letter = mb_substr($code, $i, 1, $encoding);
            $y = mt_rand($yTop, $yBottom);
            if (!$this->fixedAngle) {
                $angle = mt_rand(-15, 15);
            }
            $draw = new \ImagickDraw();
            $draw->setFont($this->mbFontFile);
            $draw->setFontSize($fontSize);
            $draw->setFillColor($foreColor);
            $image->annotateImage($draw, $x, $y, $angle, $letter);
            $fontMetrics = $image->queryFontMetrics($draw, $letter);
            $x += (int)($fontMetrics['textWidth']) + $this->mbOffset;
        }

        $image->setImageFormat('png');
        return $image->getImageBlob();
    }
361109
public function addToImageMap(
        $Type,
        $Plots,
        $Color = null,
        $Title = null,
        $Message = null,
        $HTMLEncode = false
    ) {
        if ($this->ImageMapStorageMode == null) {
            $this->initialiseImageMap();
        }

        /* Encode the characters in the imagemap in HTML standards */
        $Title = htmlentities(
            str_replace("&#8364;", "\u20AC", $Title),
            ENT_QUOTES,
            "ISO-8859-15"
        );
        if ($HTMLEncode) {
            $Message = str_replace(
                "&gt;",
                ">",
                str_replace(
                    "&lt;",
                    "<",
                    htmlentities($Message, ENT_QUOTES, "ISO-8859-15")
                )
            );
        }

        if ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION) {
            if (!isset($_SESSION)) {
                $this->initialiseImageMap();
            }
            $_SESSION[$this->ImageMapIndex][] = [$Type, $Plots, $Color, $Title, $Message];
        } elseif ($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE) {
            $Handle = fopen(
                sprintf("%s/%s.map", $this->ImageMapStorageFolder, $this->ImageMapFileName),
                'a'
            );
            fwrite(
                $Handle,
                sprintf(
                    "%s%s%s%s%s%s%s%s%s\r\n",
                    $Type,
                    IMAGE_MAP_DELIMITER,
                    $Plots,
                    IMAGE_MAP_DELIMITER,
                    $Color,
                    IMAGE_MAP_DELIMITER,
                    $Title,
                    IMAGE_MAP_DELIMITER,
                    $Message
                )
            );
            fclose($Handle);
        }
    }
929305
protected function drawScratch($img, $imageWidth, $imageHeight, $hex)
    {
        $rgb = $this->hexToRgb($hex);

        imageline(
            $img,
            mt_rand(0, floor($imageWidth / 2)),
            mt_rand(1, $imageHeight),
            mt_rand(floor($imageWidth / 2), $imageWidth),
            mt_rand(1, $imageHeight),
            imagecolorallocate($img, $rgb['r'], $rgb['g'], $rgb['b'])
        );
    }
914802
protected function drawExtendedBars($im, $plus) {
        $temp_text = $this->text . $this->keys[$this->checksumValue];
        $rememberX = $this->positionX;
        $rememberH = $this->thickness;

        // We increase the bars
        // First 2 Bars
        $this->thickness = $this->thickness + intval($plus / $this->scale);
        $this->positionX = 0;
        $this->drawSingleBar($im, CINBarcode::COLOR_FG);
        $this->positionX += 2;
        $this->drawSingleBar($im, CINBarcode::COLOR_FG);

        // Attemping to increase the 2 following bars
        $this->positionX += 1;
        $temp_value = $this->findCode($temp_text[1]);
        $this->drawChar($im, $temp_value, false);

        // Center Guard Bar
        $this->positionX += 36;
        $this->drawSingleBar($im, CINBarcode::COLOR_FG);
        $this->positionX += 2;
        $this->drawSingleBar($im, CINBarcode::COLOR_FG);

        // Attemping to increase the 2 last bars
        $this->positionX += 37;
        $temp_value = $this->findCode($temp_text[12]);
        $this->drawChar($im, $temp_value, true);

        // Completly last bars
        $this->drawSingleBar($im, CINBarcode::COLOR_FG);
        $this->positionX += 2;
        $this->drawSingleBar($im, CINBarcode::COLOR_FG);

        $this->positionX = $rememberX;
        $this->thickness = $rememberH;
    }
174999
protected function _tag_open_BARCODE($param)
    {
        if (!isset($param['type'])) {
            $param['type'] = 'C39';
        }
        if (!isset($param['value'])) {
            $param['value']    = 0;
        }
        if (!isset($param['label'])) {
            $param['label']    = 'label';
        }
        if (!isset($param['style']['color'])) {
            $param['style']['color'] = '#000000';
        }

        $param['type'] = strtoupper($param['type']);
        if (!isset($param['dimension'])) {
            $param['dimension'] = '1D';
        }

        $this->parsingCss->save();
        $this->parsingCss->analyse('barcode', $param);
        $this->parsingCss->setPosition();
        $this->parsingCss->fontSet();

        $x = $this->pdf->GetX();
        $y = $this->pdf->GetY();
        $w = $this->parsingCss->value['width'];
        if (!$w) {
            $w = $this->cssConverter->convertToMM('50mm');
        }
        $h = $this->parsingCss->value['height'];
        if (!$h) {
            $h = $this->cssConverter->convertToMM('10mm');
        }
        $txt = ($param['label'] !== 'none' ? $this->parsingCss->value['font-size'] : false);
        $c = $this->parsingCss->value['color'];
        $infos = $this->pdf->myBarcode($param['value'], $param['type'], $x, $y, $w, $h, $txt, $c, $param['dimension']);

        $this->_maxX = max($this->_maxX, $x+$infos[0]);
        $this->_maxY = max($this->_maxY, $y+$infos[1]);
        $this->_maxH = max($this->_maxH, $infos[1]);
        $this->_maxE++;

        $this->pdf->SetXY($x+$infos[0], $y);

        $this->parsingCss->load();
        $this->parsingCss->fontSet();

        return true;
    }
935670
protected function applyFilter($im, $filterType, $arg0 = 0, $arg1 = 0, $arg2 = 0)
    {
        $imgW = imagesx($im);
        $imgH = imagesy($im);

        $out = imagecreatetruecolor($imgW, $imgH);
        imagesavealpha($out, true);
        $trans = imagecolorallocatealpha($out, 0, 0, 0, 127);
        imagefill($out, 0, 0, $trans);
        imagecolortransparent($out, $trans);

        for ($x = 0; $x < $imgW; $x++) {
            for ($y = 0; $y < $imgH; $y++) {
                $rgb = imagecolorat($im, $x, $y);
                $rgba = imagecolorsforindex($im, $rgb);
                $a = $rgba['alpha'];
                $r = $rgba['red'];
                $g = $rgba['green'];
                $b = $rgba['blue'];
                switch ($filterType) {
                    case self::IMG_COL:
                        $r = $arg0;
                        $g = $arg1;
                        $b = $arg2;
                        break;
                    case self::IMG_MUL:
                        $rgba2 = imagecolorsforindex($arg0, imagecolorat($arg0, $x, $y));
                        $r = $r * $rgba2['red'] / 255;
                        $g = $g * $rgba2['green'] / 255;
                        $b = $b * $rgba2['blue'] / 255;
                        break;
                    case self::IMG_ADD_NEG:
                        $rgba2 = imagecolorsforindex($arg0, imagecolorat($arg0, $x, $y));
                        // cap color values to 255
                        $r = min(255, $r + 255 - $rgba2['red']);
                        $g = min(255, $g + 255 - $rgba2['green']);
                        $b = min(255, $b + 255 - $rgba2['blue']);
                        break;
                }
                $val = imagecolorallocatealpha($im, $r, $g, $b, $a);
                imagesetpixel($out, $x, $y, $val);
            }
        }
        return $out;
    }
897481
private function drawBorderInside($color, $borderWidth, $borderHeight) {
        $this->imageWidth = $this->image->getWidth();
        $this->imageHeight = $this->image->getHeight();

        $rect = new ImagickDraw();
        $rect->setStrokeColor($color);
        $rect->setFillColor($color);
        $rect->setStrokeAntialias(false);

        // Left
        $rect->rectangle(0, 0, $borderWidth - 1, $this->imageHeight);

        // Right
        $rect->rectangle($this->imageWidth - $borderWidth, 0, $this->imageWidth, $this->imageHeight);

        // Top
        $rect->rectangle(0, 0, $this->imageWidth, $borderHeight - 1);

        // Bottom
        $rect->rectangle(0, $this->imageHeight - $borderHeight, $this->imageWidth, $this->imageHeight);

        // Draw the border
        $this->imagick->drawImage($rect);
    }
1025271
protected function imagickDrawText($image, $text)
    {
        $draw = new \ImagickDraw();
        $draw->setFont($this->font);

        $draw->setFontSize($this->height * 0.8);
        $draw->setFillColor(new \ImagickPixel('#333333'));
        $draw->setStrokeAntialias(true);
        $draw->setTextAntialias(true);
        $metrics = $image->queryFontMetrics($draw, $text);
        $draw->annotation(0, $metrics['ascender'], $text);
        $image->drawImage($draw);
        $draw->destroy();
        return $image;
    }
286204
public function draw(): void
	{
		// Don't draw progess bar if there are 0 items

		if($this->items === 0)
		{
			return;
		}

		// Calculate percent

		$percent = (float) min(($this->progress / $this->items), 1);

		// Build progress bar

		$progressBar = $this->buildProgressBar($percent);

		// Draw progressbar

		$this->output->write("\r" . $this->prefix . $progressBar);

		// If we're done then we'll add a newline to the output

		if($this->progress === $this->items)
		{
			$this->output->write(PHP_EOL);
		}
	}