An error occurs when running Imagick's readImage() method
烛光
烛光 2019-07-23 11:41:11
0
2
2082

The code is as follows:

function pdf2png($pdf,$path,$page=-1)
 {  
    if(!extension_loaded('imagick'))
    {  
        return false;  
    }  
    if(!file_exists($pdf))
    {  
        return false;  
    }  
    $im = new Imagick();  
    $im->setResolution(120,120);  
    $im->setCompressionQuality(100);
    if($page==-1)   
       $im->readImage($pdf);
    else
       $im->readImage($pdf."[".$page."]");
    foreach ($im as $Key => $Var)
    {  
        $Var->setImageFormat('png');  
        $filename = $path."/". md5($Key.time()).'.png';
        if($Var->writeImage($filename) == true)
        {  
            $Return[] = $filename;  
        }  
    }  
    return $Return;  
 }  
 $path="tmp/tmp";//请确保当前目录下有这个文件夹,由于一直要用,所以就不加检测了
$s=pdf2png("./tmp/test.pdf",$path);
 $scount=count($s);
 for($i=0;$i<$scount;$i++)
 {
    echo "<div align=center><font color=red>Page ".($i+1)."</font><br><a href=\"".$s[$i]."\" target=_blank><img border=3 height=120 width=90 src=\"".$s[$i]."\"></a></div><p>";
 }

The pdf file also exists.

An error will be reported when using the Imagick extension to execute the readImage() method. The parallel extension has been added

QQ图片20190723113820.png

and ghostscript is also installed under windows. The error is as follows:

QQ图片20190723113825.png

烛光
烛光

活到老学到老

reply all(2)
AAA David

No error is reported when reporting errors. Installing gshostscript is of no use. Just readimage pictures and PDFs and report errors

眺望未来

Use Imagick extension to execute to readImage

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template