Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed
Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed
〜〜
No such file or directory @ error/pdf.c/ReadPDFImage/664
といったようなエラーがでる。 これはphpのimage
$pdf = new imagick( 'name.pdf[0]' );
ってやったらでました。
可能性
664ってとこから、どうもGhostScriptが見つかってないっぽい。
ということで phpから
$results = shell_exec('/usr/bin/convert /usr/home/html/a.pdf /usr/home/html/b.png >/tmp/err.txt 2>&1');
echo "<pre>$results</pre>";
で /tmp/err.txt にエラーが出てるので確認。こんなのが出た
convert: Postscript delegate failed `/usr/home/html/a.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/664.
convert: missing an image filename `/usr/home/html/b.png ' @ error/convert.c/ConvertImageCommand/3015.
解決策1(解決になってないけど)
「vi /etc/sudoers」に
#sorry, you must have a tty to run sudoというエラーがでるので↓をコメントアウト
#Defaults requiretty
# 末尾に追加
%username ALL=NOPASSWD: /usr/bin/convert
とphpの実行ユーザ名で許可する
参考
こんな感じのコードでテストしました。
<?php
#sudo してpdf → png変換
$results = shell_exec('/usr/bin/sudo /usr/bin/convert /usr/home/chz3005002/html/test/1/b.pdf /usr/home/chz3005002/html/test/1/bdesuyo.png >/tmp/err.txt 2>&1');
echo "<pre>$results</pre>";
# phpの実行ユーザ名は /tmp/whoami.txt に出力
$results = shell_exec('/usr/bin/whoami >/tmp/whoami.txt 2>&1');
echo "<pre>$results</pre>";
こうすることで、そもそもphpからのconvertが出来ない件は一応解決。つまり権限の問題だったっぽい。 ※phpのバージョンを複数いれてるからその辺りが関係あるのかな。
ただこれだと結局imagick関数は使えないのでその場合のは未解決