我在一个名为downloads的文件夹中有一些pdf,我想在php中使用imagick以jpg格式生成缩略图,但是我因为无法创建临时文件而收到错误。 我得到的错误是:
Fatal error: Uncaught exception 'ImagickException' with message 'unable to create temporary file `/home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/images/downloads/demoPDF.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/397' in /home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/imagickTest2.php:14 Stack trace: #0 /home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/imagickTest2.php(14): Imagick->__construct('/home/vrwebqbj/...') #1 {main} thrown in /home/vrwebqbj/public_html/virtuereal.com/KyoritsuElectric/admin/imagickTest2.php on line 14
到目前为止,我尝试过:
<?php
error_reporting(1);
$source = __DIR__."/images/downloads/demoPDF.pdf"; //Source PDF File
$target = "myfile.jpg"; // Output File
/*function genPdfThumbnail($source, $target)
{*/
//$source = realpath($source);
$target = dirname($source).DIRECTORY_SEPARATOR.$target;
//echo $target;
//echo __DIR__;
$im = new Imagick($source."[0]"); // 0-first page, 1-second page
$im->setImageColorspace(255); // prevent image colors from inverting
$im->setimageformat("jpeg");
$im->thumbnailimage(160, 120); // width and height
$im->writeimage($target);
$im->clear();
$im->destroy();
// }
//genPdfThumbnail('images/downloads/demoPDF.pdf','myfile.jpg');
?>
<img src="KyoritsuElectric/admin/images/downloads/myfile.jpg" />