我已经成功安装了Imagick dll。我已经关注了stackoverflow exmple
How do I convert a PDF document to a preview image in PHP?
以下是我的代码
<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
?>
但我现在收到以下错误
Fatal error: Uncaught exception 'ImagickException' with message 'UnableToOpenBlob `demo.pdf': No such file or directory @ error/blob.c/OpenBlob/2657' in D:\xampp\htdocs\learn\index.php:2 Stack trace: #0 D:\xampp\htdocs\learn\index.php(2): Imagick->__construct('demo.pdf[0]') #1 {main} thrown in D:\xampp\htdocs\learn\index.php on line 2
Imagick dll安装了螺旋桨
答案 0 :(得分:0)
public function pdfToJpg($param){
$filename = $param['filename'];
$image_name = $param['image_name'];
$path = $param['path'];
$db_path = $param['db_path'];
$im = new Imagick();
$im->setResolution(220,220);
$im->readimage($filename."[0]");
$im->setImageFormat('jpeg');
$im->setImageBackgroundColor('#ffffff');
$im->flattenImages();
$image_name = $image_name.".jpg";//"save_as_name.jpg";
$imageprops = $im->getImageGeometry();
/*if ($imageprops['width'] <= 175 && $imageprops['height'] <= 300) {
// don't upscale
} else {
$im->resizeImage(175,300, imagick::FILTER_LANCZOS, 0.9, true);
}*/
$im->writeImage($path.$image_name);
if($im){
$Img = array();
$Img['status'] = 1;
$Img['image'] = ($db_path.$image_name);
return $Img;
}
$im->clear();
$im->destroy();
}
试一试