I'm getting this error trying to convert a pdf to a jpeg thumbnail:
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
Have no issues with this anywhere else, this is on a godaddy server the PATH is /sbin:/usr/sbin:/bin:/usr/bin and ghostscript is here: /usr/bin/ghostscript
but I'm not understanding [or finding any info on]:
-dname= must be followed by a valid token
here is the actual script for reference:
<?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'] . '" />';