Mike42\Escpos\ImagickEscposImage::getColumnFormatFromImage PHP 메소드

getColumnFormatFromImage() 개인적인 메소드

Operates recursively to save cloning larger image many times.
private getColumnFormatFromImage ( Imagick $im, integer $lineHeight ) : string[]
$im Imagick
$lineHeight integer Height of printed line in dots. 8 or 24.
리턴 string[]
    private function getColumnFormatFromImage(Imagick $im, $lineHeight)
    {
        $imgWidth = $im->getimagewidth();
        if ($imgWidth == $lineHeight) {
            // Return glob of this panel
            return array($this->getRasterBlobFromImage($im));
        } elseif ($imgWidth > $lineHeight) {
            // Calculations
            $slicesLeft = ceil($imgWidth / $lineHeight / 2);
            $widthLeft = $slicesLeft * $lineHeight;
            $widthRight = $imgWidth - $widthLeft;
            // Slice up (left)
            $left = clone $im;
            $left->extentimage($widthLeft, $left->getimageheight(), 0, 0);
            // Slice up (right - ensure width is divisible by lineHeight also)
            $right = clone $im;
            $widthRightRounded = $widthRight < $lineHeight ? $lineHeight : $widthRight;
            $right->extentimage($widthRightRounded, $right->getimageheight(), $widthLeft, 0);
            // Recurse
            $leftBlobs = $this->getColumnFormatFromImage($left, $lineHeight);
            $rightBlobs = $this->getColumnFormatFromImage($right, $lineHeight);
            return array_merge($leftBlobs, $rightBlobs);
        } else {
            /* Image is smaller than full width */
            $im->extentimage($lineHeight, $im->getimageheight(), 0, 0);
            return array($this->getRasterBlobFromImage($im));
        }
    }