如果您刚刚上传了 PDF 文件并想从第一页生成图片,则需要在图片名称中添加 [0] 作为文本字符串。
$filename = getSafeFileName($uploaddir,basename($_FILES['brochure_pdf']['name'], $overwrite));
$uploadfile = $uploaddir . $filename;
if (move_uploaded_file($_FILES['brochure_pdf']['tmp_name'], $uploadfile)) {
$brochure_pdf = $filename;
$im = new Imagick();
$im->setResolution(80,80);
$im->readimage($uploadfile."[0]");
$im->setImageFormat('jpeg');
$image_name = "save_as_name.jpg";
$imageprops = $im->getImageGeometry();
if ($imageprops['width'] <= 175 && $imageprops['height'] <= 300) {
// 不要进行放大
} else {
$im->resizeImage(175,300, imagick::FILTER_LANCZOS, 0.9, true);
}
$im->writeImage($uploaddir .$image_name);
$im->clear();
$im->destroy();