尝试在Godaddy服务器上使用Imagick创建PDF的jpeg拇指图像时出错

时间:2016-07-08 17:09:23

标签: php ghostscript imagick

我在尝试将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服务器上PATH是/ 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'] . '" />';

1 个答案:

答案 0 :(得分:0)

尝试更改线路......

$img = new Imagick($pdf.'[0]');

为...

$img = new Imagick($pdf.'[1]');

出于某种原因,Ghostscript不接受零参数作为第一页,必须是&#34; 1&#34;。