我在尝试将pdf转换为jpeg缩略图时收到此错误:
Fatal error: Uncaught exception 'ImagickException' with message
'PDFDelegateFailed `[ghostscript library]
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT
-dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2
"-sDEVICE=pam" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"
-dUseCIEColor -dFirstPage=1 -dLastPage=1
"-sOutputFile=/tmp/magick-1514TynhowIwvsS8%d"
"-f/tmp/magick-1514ToUFRp0QWKlG"
"-f/tmp/magick-1514zEMWRNGv55Od"':
-dname= must be followed by a valid token
@ error/pdf.c/InvokePDFDelegate/263'
in /home/domain/public_html/pdfPreview.php:46
Stack trace: #0 /home/domain/public_html/pdfPreview.php(46):
Imagick->__construct('./assets/whatsn...')
#1 {main} thrown in
/home/domain/public_html/pdfPreview.php on line 46
在其他任何地方都没有问题,这是在 godaddy 服务器上,路径是
/sbin:/usr/sbin:/bin:/usr/bin,ghostscript 在这里:/usr/bin/ghostscript但我不明白[或找到任何信息]:
-dname= must be followed by a valid token
以下是实际脚本供参考:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo getenv('PATH') ;
echo "<pre>";
system("which ghostscript");
system("ghostscript --version");
echo "</pre>";
$pdf = './assets/whatsnew/36215A_IG_040915.pdf';
$id = '1';
$filename = basename($pdf, '.pdf');
$path_parts = pathinfo($pdf);
$dir = $path_parts['dirname'];
$filename = $path_parts['filename'];
$filename = strtolower($filename);
$filename = preg_replace("/[^a-z0-9_'s-]/", "", $filename);
$filename = preg_replace("/['s-]+/", " ", $filename);
$filename = preg_replace("/['s_]/", "-", $filename);
$thumb = $dir . '/' . $filename . '-' . $id . '.jpg';
echo $thumb;
if(!file_exists($thumb)){
if(file_exists($pdf)){
$img = new Imagick($pdf.'[0]');
$img->scaleImage(85,110);
$img->setImageFormat('jpg');
$img->writeImage($thumb);
}else{
$thumb = $dir . '/pdf-default.gif';
}
}
return '<img src="' . $thumb . '" class="tip-image" alt="' . $path_parts['filename'] . '" />';
尝试更改行...
$img = new Imagick($pdf.'[0]');
自。。。
$img = new Imagick($pdf.'[1]');
出于某种原因,Ghostscript 不接受零参数作为第一页,必须是"1"。