Home  >  Q&A  >  body text

An error occurs when running Imagick's readImage() method

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

烛光烛光1888 days ago2046

reply all(2)I'll reply

  • AAA David

    AAA David2021-07-10 18:14:23

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

    reply
    0
  • 眺望未来

    眺望未来2019-07-24 21:28:48

    Use Imagick extension to execute to readImage

    reply
    0
  • Cancelreply