アプリ版:「スタンプのみでお礼する」機能のリリースについて

レンタルサーバ(lolipop)でディレクトリに置いてあるPDFファイルを画像として表示したいと思ってますが、何故PHP初心者の為、ネットで探してみましたが、エラーになりなかなか上手くいきません。
おわかりになる方、宜しくお願い致します。

あるディレクトリに複数のPDFファイルがあります(ページ数はすべて1ページのみ)
そのPDFを画像としてブラウザに並べて表示して、クリックすると実際のPDFが表示されるしくみを作りたいです。

解り難い表現でしたら、申し訳ありません。
お解かりになる方、宜しくお願い致します。

A 回答 (7件)

>Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `0011.pdf': No such file or directory'



との事なので、"GhostScript"でうまく処理できていないという事だと思います。
一度プロバイダーに確認されるのが良いのではと思います。
    • good
    • 0
この回答へのお礼

ご連絡遅くなりました。
色々と有難うございます。とりあえずもう少し、いろいろと挑戦してみようと思います。

有難うございました

お礼日時:2012/06/18 12:01

http://www.favorite-labo.org/view/218
こちらも確認を。
ロリポのImagick関係の問題は頻出ですので。

この回答への補足

有難うございます。
リンクも参照してみました。

結果
Array ( [0] => Version: ImageMagick 6.4.3 2011-07-13 Q16 http://www.imagemagick.org [1] => Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC [2] => )

使用サーバーのバージョンは6.4.3ということがわかりました。

いろいろ有難うございます。
もう少し調べてみようと思います

補足日時:2012/06/17 17:44
    • good
    • 0

$im = new imagick($file."[0]"); <<これは試してもらえましたか?



エラーメッセージ見ているとimagicの引数は配列みたいですね。

上記を、下記に変えたらどうなりますか?

$im = new Imagick(); // 引数無し
$im->readImage($file."[0]"); // 追加

この回答への補足

ありがとうございます。変更してみました。
<?php
// 読み込む PDF をフルパスで指定
$file = '0011.pdf';
// サムネイルを作成するページを指定
$page = 1;
// 実際の指定では、1ページが0になるので、調整
$page = $page - 1;
$im = new Imagick(); // 引数無し
$im->readImage($file."[0]"); // 追加
// PNG 形式に変換
$im->setImageFormat("png");
// 長辺が 300 ピクセルになるようにリサイズ
$im->thumbnailImage(300, 300, true);
// 表示
header("Content-Type: image/png");
echo $im;
?>

が、エラーになります

ERROR: /undefined in /BXlevel Operand stack: 1 --dict:6/6(ro)(G)-- リ皋_ロテレェ+~l霄:碩E鰈pQ Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- Dictionary stack: --dict:1127/1686(ro)(G)-- --dict:0/20(G)-- --dict:107/200(L)-- --dict:107/200(L)-- --dict:104/127(ro)(G)-- --dict:241/347(ro)(G)-- --dict:18/24(L)-- Current allocation mode is local
Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `0011.pdf': No such file or directory' in /xxx/xxx/0/xxx/web/pdf/pdf.php:23 Stack trace: #0 /xxx/xxx/0/xxx/web/pdf/pdf.php(23): Imagick->readimage('0011.pdf[0]') #1 {main} thrown in /xxx/xxx/0/xxx/web/pdf/pdf.php on line 23

いろいろ申し訳ありません

補足日時:2012/06/17 16:19
    • good
    • 0

先ほど、フルパスはダメだと解っているので、


$file = '/xxx/xxx/0/xxx/web/pdf/0011.pdf';
をファイル名だけに
$file = '0011.pdf';

$im = new imagick("$file[$page]");

$im = new imagick($file."[0]");

でどうでしょうか?

この回答への補足

度々有難うございます
フルパスは解除し、下記にて調整しました

<?php
// 読み込む PDF をフルパスで指定
$file = '0011.pdf';
// サムネイルを作成するページを指定
$page = 1;
// 実際の指定では、1ページが0になるので、調整
$page = $page - 1;
$im = new imagick("$file[0]");
// PNG 形式に変換
$im->setImageFormat("png");
// 長辺が 300 ピクセルになるようにリサイズ
$im->thumbnailImage(300, 300, true);
// 表示
header("Content-Type: image/png");
echo $im;
?>

表示は下記です

Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `/xxx/xxx/0/xxx/web/pdf/0': No such file or directory' in /xxx/xxx/0/xxx/web/pdf/pdf.php:22 Stack trace: #0 /xxx/xxx/0/xxx/web/pdf/pdf.php(22): Imagick->__construct('0') #1 {main} thrown in /xxx/xxx/0/xxx/web/pdf/pdf.php on line 22

ファイルが見つからないというエラーでしょうか。
色々と恐れ入ります。

補足日時:2012/06/17 15:58
    • good
    • 0

もしかするとこの部分が、



$im = new imagick($file[$page]);
$im = new imagick("$file[$page]");

ではありませんか?

この回答への補足

ありがとうございます。
いろいろ試してはいますが、エラーが続いてます。。。

現状、
<?php
// 読み込む PDF をフルパスで指定
$file = '/xxx/xxx/0/xxx/web/pdf/0011.pdf';
// サムネイルを作成するページを指定
$page = 1;
// 実際の指定では、1ページが0になるので、調整
$page = $page - 1;
$im = new imagick("$file[$page]");
// PNG 形式に変換
$im->setImageFormat("png");
// 長辺が 300 ピクセルになるようにリサイズ
$im->thumbnailImage(300, 300, true);
// 表示
header("Content-Type: image/png");
echo $im;
?>

にて試していますが、


Fatal error: Uncaught exception 'ImagickException' with message 'Safe mode restricts user to read image: /' in /xxx/xxx/0/xxx/web/pdf/pdf.php:22 Stack trace: #0 /xxx/xxx/0/xxx/web/pdf/pdf.php(22): Imagick->__construct('/') #1 {main} thrown in /xxx/xxx/0/xxx/web/pdf/pdf.php on line 22

となります。
ディレクトリのパーミッションは755です。777でも試しましたが、エラーになります。
パーミッションは755で問題ないのでしょうか。

何かと恐れ入ります。お時間あれば、宜しくお願いいたします

補足日時:2012/06/17 15:41
    • good
    • 0

>Fatal error: Uncaught exception 'ImagickException' with message 'Safe mode restricts user to read image: /' in /xxx/xxx/0/xxx/web/pdf/pdf.php:27 Stack trace: #0 /xxx/xxx/0/xxx/web/pdf/pdf.php(27): Imagick->__construct('/') #1 {main} thrown in /xxx/xxx/0/xxx/web/pdf/pdf.php on line 27



イメージファイル名を、"/"(スラッシュ)と認識して、ファイルで無いと怒られています。

パス付のファイルの指定に問題がありそうです。
ちょっと詳しく調べている時間が無いのですが、
phpのスクリプトがphpと同じフォルダーにあるので、

$file = '/xxx/xxxx/0/xxx/web/pdf/0011.pdf';



$file = '0011.pdf';

に変更すればなんとかなりませんか?

この回答への補足

有難うございます。
変更してみましたが、下記のエラーになります

Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `/xxx/xxx/0/xxx/web/pdf/0': No such file or directory' in /xxx/xxx/0/xxx/web/pdf/pdf.php:22 Stack trace: #0 /xxx/xxx/0/xxx/web/pdf/pdf.php(22): Imagick->__construct('0') #1 {main} thrown in /xxx/xxx/0/xxx/web/pdf/pdf.php on line 22

補足日時:2012/06/17 15:07
    • good
    • 0

ImageMagickを使っているのでしょうか?



具体的にどういう設定で、どういうロジックでエラーになるのかを
説明頂かないと、アドバイスするのは難しいと思います。

この回答への補足

ありがとうございます。

インターネットで調べたところ、imagickを使えばPDF→画像に処理できるところは理解できました。
ンタルサーバ上(lolipop)でimagickを使えることもわかったのですが、ネットで見つけたPHPプログラムにて下記のように書いてもエラーになります。

<?php
// 読み込む PDF をフルパスで指定
$file = '/xxx/xxxx/0/xxx/web/pdf/0011.pdf';
// サムネイルを作成するページを指定
$page = 1;
// 実際の指定では、1ページが0になるので、調整
$page = $page - 1;
$im = new imagick($file[$page]);
// PNG 形式に変換
$im->setImageFormat("png");
// 長辺が 300 ピクセルになるようにリサイズ
$im->thumbnailImage(300, 300, true);
// 表示
header("Content-Type: image/png");
echo $im;
?>

エラーは:
Fatal error: Uncaught exception 'ImagickException' with message 'Safe mode restricts user to read image: /' in /xxx/xxx/0/xxx/web/pdf/pdf.php:27 Stack trace: #0 /xxx/xxx/0/xxx/web/pdf/pdf.php(27): Imagick->__construct('/') #1 {main} thrown in /xxx/xxx/0/xxx/web/pdf/pdf.php on line 27

色々調べてはいるんですが、PHP初心者の為、何がいけないのかのイメージがわきません。。。
宜しくお願い致します

補足日時:2012/06/17 13:51
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!