[英]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.