-1

私はphpとghostscriptを使ってpdfを画像に変換して表示します

<?php
if(empty($_GET['page'])) die;
$numPage=$_GET['page'];
header('Content-type:image/jpeg');
system("gs ".
"-dNOPAUSE ".
"-sDEVICE=jpeg ".
"-dFirstPage={$numPage} ".
"-dLastPage={$numPage} ".
"-sOutputFile=%stdout ".
"-dJPEGQ=90 ".
"-r100x100 ".
"-q file.pdf ".
"-c quit");
?>

答えてくれてありがとう

4

1 に答える 1

0
  1. PHPマニュアルpassthrusystem
    よると This function[passthru()] should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser.

  2. gs man ページ%stdoutに変更:-

    You can also send output to stdout for piping with the switch

            -sOutputFile=-
    

以下のコードで修正できます。

<?php

if(empty($_GET['page'])) die;

$numPage=$_GET['page'];

header('Content-type:image/jpeg');

passthru("gs ".
"-dNOPAUSE ".
"-sDEVICE=jpeg ".
"-dFirstPage={$numPage} ".
"-dLastPage={$numPage} ".
"-sOutputFile=- ".
"-dJPEGQ=90 ".
"-r100x100 ".
"-q file.pdf ".
"-c quit");

?>
于 2013-02-02T16:41:00.603 に答える