Php 如何在fpdf中显示png和jpeg图像

Php 如何在fpdf中显示png和jpeg图像,php,Php,当我打开pdf时,png文件没有打开,我有很多文件有png和jpeg图像,所以我想通过fpdf将png和jpeg图像显示为pdf 这是我的控制器代码 function pdf($clipid){ require_once(APPPATH.'libraries/fpdi/fpdf.php'); } $immlogo=$this->immlogo; list($imm_logo_w, $imm_logo_h) = getimagesize($i

当我打开pdf时,png文件没有打开,我有很多文件有png和jpeg图像,所以我想通过fpdf将png和jpeg图像显示为pdf

这是我的控制器代码

function pdf($clipid){

   require_once(APPPATH.'libraries/fpdi/fpdf.php');
    }

        $immlogo=$this->immlogo;
        list($imm_logo_w, $imm_logo_h) = getimagesize($immlogo);
         $imm_logo_w = $imm_logo_w * 0.30;
         $imm_logo_h = $imm_logo_h * 0.30;

         $pdf=new FPDF('P','mm','a4');
$b=1;
         foreach($clip_ids_for_pdf as $clipid)
         {
         $cliparrdetails=$this->getClipDetails($clipid);
         extract($cliparrdetails);
        $files=$clipfile;

        $oth_text="Date: ".$clipdatejs." | Edition: ".$pubcity." | Page: ".$pageno." | Source: ".$clipbyline." | Clip size (cm): W: ".$clipw." H: ".$cliph;

            $line_width=210;

            /// Start generation of files ///

        foreach ($files as $fkey=>$fval) {
        $no=$b+1;
        $clipof='Clip: '.$b.' of '.count($clip_ids_for_pdf);
        extract($fval);
        $imgfile=$filepath.$filename;
        list($width, $height) = getimagesize($imgfile); // calculate dimensions etc
        if ($width <= 1399) {
        $new_width=$width*0.10;
        $new_height=$height*0.10;
        } else if ($width >= 1400) {
        $new_width=$width*0.08;
        $new_height=$height*0.08;
        }       
        $b++;




        $x=(210-$new_width)/2;
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',18);
        $pdf->Cell(0,8,$pubname,0,1,'C',0);
        $pdf->SetFont('Arial','B',12);
        $pdf->Cell(0,5,$headline,0,1,'C',0);
        $pdf->SetFont('Arial','B',8);
        $pdf->Cell(0,5,$oth_text,0,1,'C',0);
        $pdf->Image($immlogo,170,3,$imm_logo_w,$imm_logo_h);
        $pdf->Line(4,28,$line_width,28);
        $pdf->Image($imgfile,$x,32,$new_width,$new_height,'JPG');
        $pdf->SetFont('Arial','B',7);
        $pdf->Cell(0,5,$clipof,0,1,'C',0);


         } 


        }
        $pdf->Output();

}

$pdf->Image($imgfile,$x,32,$new_width,$new_height,'JPG');在这里你可以硬编码为JPG为PNG它将如何工作。要在FPDF中显示PNG图像,允许对PNG进行一些限制:最多8位(256级)索引颜色的灰度真彩色(24位)TCPDF比FPDF先进,如果需要添加PNG图像,您可以使用它
function Image ($file, $x=null, $y=null, $w=0, $h=0, $type='', $link=''){

    if(!isset($this->images[$file]))
    {

        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=='jpg')
        {

            $type='jpg';

            }

        $mtd='_parse'.$type;
        if(!method_exists($this,$mtd))
            $this->Error('Unsupported image type: '.$type);
        $info=$this->$mtd($file);
        $info['i']=count($this->images)+1;
        $this->images[$file]=$info;
    }
    else
        $info=$this->images[$file];

    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'];

    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;
    $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);
}