[英]How to get JPEG image from PDF using other php library than Imagick?
[英]How to convert pdf file to image using Imagick library in PHP?
我已经成功安装了 Imagick dll。我遵循了以下 stackoverflow 示例
以下是我的代码
<?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 安装 propelry
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();
}
尝试一下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.