NFePHP\Extras\PdfNFePHP::Image PHP Method

Image() public method

* * ***************************************************************************** * Public methods * * *****************************************************************************
public Image ( $file, $x = null, $y = null, $w, $h, $type = '', $link = '', $isMask = false, $maskImg )
    function Image($file, $x = null, $y = null, $w = 0, $h = 0, $type = '', $link = '', $isMask = false, $maskImg = 0)
    {
        //Put an image on the page
        if (!isset($this->images[$file])) {
            //First use of this image, get info
            if ($type == '') {
                $pos = strrpos($file, '.');
                if (!$pos) {
                    $this->Error('Image file has no extension and no type was specified: ' . $file);
                }
                $type = substr($file, $pos + 1);
            }
            $type = strtolower($type);
            if ($type == 'png') {
                $info = $this->_parsepng($file);
                if ($info == 'alpha') {
                    return $this->ImagePngWithAlpha($file, $x, $y, $w, $h, $link);
                }
            } else {
                if ($type == 'jpeg') {
                    $type = 'jpg';
                }
                $mtd = '_parse' . $type;
                if (!method_exists($this, $mtd)) {
                    $this->Error('Unsupported image type: ' . $type);
                }
                $info = $this->{$mtd}($file);
            }
            if ($isMask) {
                if (in_array($file, $this->tmpFiles)) {
                    $info['cs'] = 'DeviceGray';
                }
                //hack necessary as GD can't produce gray scale images
                if ($info['cs'] != 'DeviceGray') {
                    $this->Error('Mask must be a gray scale image');
                }
                if ($this->PDFVersion < '1.4') {
                    $this->PDFVersion = '1.4';
                }
            }
            $info['i'] = count($this->images) + 1;
            if ($maskImg > 0) {
                $info['masked'] = $maskImg;
            }
            $this->images[$file] = $info;
        } else {
            $info = $this->images[$file];
        }
        //Automatic width and height calculation if needed
        if ($w == 0 && $h == 0) {
            //Put image at 72 dpi
            $w = $info['w'] / $this->k;
            $h = $info['h'] / $this->k;
        } elseif ($w == 0) {
            $w = $h * $info['w'] / $info['h'];
        } elseif ($h == 0) {
            $h = $w * $info['h'] / $info['w'];
        }
        //Flowing mode
        if ($y === null) {
            if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) {
                //Automatic page break
                $x2 = $this->x;
                $this->AddPage($this->CurOrientation, $this->CurPageFormat);
                $this->x = $x2;
            }
            $y = $this->y;
            $this->y += $h;
        }
        if ($x === null) {
            $x = $this->x;
        }
        if (!$isMask) {
            $this->_out(sprintf('q %.2F 0 0 %.2F %.2F %.2F cm /I%d Do Q', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k, $info['i']));
        }
        if ($link) {
            $this->Link($x, $y, $w, $h, $link);
        }
        return $info['i'];
    }