[英]Imagick/Ghostscript error with PDF input
我已经使用imagick PHP的DLL在Windows上安装了ImageMagick。
我需要将PDF转换为JPEG。 因此,我还安装了Ghostcript。
如果我运行此命令:
convert rose.pdf rose.jpg
它运作良好。 但是,如果我尝试使用PHP在我的Web环境中重现相同的功能:
$im = new imagick('test_pdf.pdf[0]' );
$im->setImageColorspace(255);
$im->setCompression(Imagick::COMPRESSION_JPEG);
$im->setCompressionQuality(100);
$im->setImageFormat('pdf');
$im->writeImage('thumb.jpg');
然后我的页面就掉了。
我认为Imagick PHP无法将PDF转换为JPEG,因为它不知道如何使用Ghostscript库gslib
。
但是,使用此代码,我可以将PNG转换为JPEG。
我试图在delegates.xml
.xml中进行编辑,但是我不确定该如何完成。
这是我的delegates.xml
中的相关行:
<delegate decode="pdf" encode="eps" mode="bi" \
command=""@PSDelegate@" \
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 \
-dEPSCrop \
-sDEVICE=epswrite "-sOutputFile=%o" -- "%i""/>
<delegate decode="pdf" encode="ps" mode="bi" \
command=""@PSDelegate@" \
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 \
-dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 \
-sDEVICE=pswrite "-sOutputFile=%o" -- "%i""/>
我尝试使用-verbose
运行ImageMagick以获得其他提示:
convert -verbose 2.pdf 1.jpg
结果:
[ghostscript library] Files/gs/gs9.15/bin/gswin64c.exe" -q -dQUIET -dSAFER -dBATCH
-dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2
"-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"
"-sOutputFile=C:/Users/Usuario/AppData/Local/Temp/magick-PjagmlB-%08d"
"-fC:/Users/Usuario/AppData/Local/Temp/magick-1l5fdY8X"
"-fC:/Users/Usuario/AppData/Local/Temp/magick-Fr-GsA3"
C:/Users/Usuario/AppData/Local/Temp/magick-_PjagmlB-000000
1 PNG 609x791 609x791+0+0 8-bit DirectClass 47.8KB 0.016u 0:00.031
2.pdf PDF 609x791 609x791+0+0 16-bit DirectClass 47.8KB 0.000u 0:00.031
2.pdf=>1.jpg PDF 609x791 609x791+0+0 16-bit DirectClass 131KB 0.031u 0:00.046 –
[Mon Dec 22 09:11:59.022854 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00428: Parent: child `process 6552 exited with status 255 -- Restarting. [Mon Dec 22 09:11:59.170587 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00455: Apache/2.4.9 (Win64) PHP/5.5.12 configured -- resuming normal operations -- PHP/5.5.12 configured -- resuming normal operations [Mon Dec 22 09:11:59.170587 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:42:59 [Mon Dec 22 09:11:59.170587 2014] [core:notice] [pid 6600:tid 520] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d C:/wamp/bin/apache/apache2.4.9' [Mon Dec 22 09:11:59.170587 2014] [mpm_winnt:notice] [pid 6600:tid 520] AH00418: Parent: Created child process 4484 [Mon Dec 22 09:11:59.807339 2014] [mpm_winnt:notice] [pid 4484:tid 436] AH00354: Child: Starting 64 worker threads.
$im = new imagick( __DIR__ . DIRECTORY_SEPARATOR .'test_pdf.pdf' );
var_dump($im);die;
但是在输入var_dump之前,页面会关闭。
这个对我有用 :)。 我已经尝试了几个月的安装,但没有成功。
我只是关注那个主题: 在哪里可以找到Windows wampserver 2.5的php 5.5.12的php_imagick.dll?
之后,我将C:/path/to/ImageMagick/delegates.xml复制/粘贴到C:/wamp/bin/php/php.5.5.12/ext/imagick并编辑pdf的委托标记:
<delegate decode="eps" encode="pdf" mode="bi" command=""C:\Program Files (x86)\gs\gs9.15\bin\gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -sDEVICE=pdfwrite "-sOutputFile=%o" -- "%i""/>
这是我的 delegates.xml
中的相关行。 但是,我没有使用Imagick或PHP,因此我不确定这是否是您进行更改所需的唯一更改。
首先,一种无需横向滚动即可阅读的表格。 您必须删除换行符以及我插入的换行符\\
:
<delegate decode="pdf" encode="eps" mode="bi" \
command=""/opt/local/bin/gsx" \
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 \
-dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=epswrite" \
"-sOutputFile=%o" "-f%i""/>
<delegate decode="pdf" encode="ps" mode="bi" \
command=""/opt/local/bin/gsx" \
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 \
-dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" \
"-sOutputFile=%o" "-f%i""/>
现在是原始行。 您需要水平滚动才能完全看到其原始形状:
<delegate decode="pdf" encode="eps" mode="bi" command=""/opt/local/bin/gsx" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i""/>
<delegate decode="pdf" encode="ps" mode="bi" command=""/opt/local/bin/gsx" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" "-sOutputFile=%o" "-f%i""/>
这些行来自于我的ImageMagick的Mac OS X版本,版本6.9.0-0 Q16 x86_64 2014-12-06
。
如您所见,它不使用@PSDelegate
-syntax。 相反,它包含Ghostscript可执行文件的完整路径,在我的情况下为/opt/local/bin/gsx
。
对于您而言,它可能应该是Ghostscript可执行文件的完整Windows路径,该文件通常名为gswin32c.exe
或gswin64c.exe
。
您使用奇怪的@PSDelegate
问题可能是由于您在安装Ghostscript 之前先安装ImageMagick / Imagick, 然后才安装Ghostscript。
也许您应该尝试在您的delegates.xml
文件中的以下几行中安装Windows / Ghostscript:
<delegate decode="pdf" encode="eps" mode="bi" command=""C:/Program Files/gs/gs9.15/bin/gswin64c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i""/>
<delegate decode="pdf" encode="ps" mode="bi" command=""C:/Program Files/gs/gs9.15/bin/gswin64c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" "-sOutputFile=%o" "-f%i""/>
注意 ,您不需要使用反斜杠(' \\
')- Windows上的Ghostscript和ImageMagick可以使用正斜杠(' /
')。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.