简体   繁体   English

如何在PHP中使用ImageMagick显示图像序列

[英]How to display sequence of images using ImageMagick in PHP

for($i = 0; $i < 2; $i++) {
    $im = new imagick('fileuploads/filename.pdf['.$i.']');
    $im->setImageFormat('jpg');
    header('Content-Type: image/jpeg');
    echo $im;
}

The above code displays only the first page of the PDF file. 上面的代码仅显示PDF文件的第一页。

HTTP allows only one resource per url so when visits your preview url he can only see one image like http://example.com/a.jpg would open only a.jpg it cannot open b.jpg at the same time.so your only option is to create a big image and copy the pdf pages you want to show in the preview.I am not sure but you may try the code below HTTP每个网址只允许使用一种资源,因此,当您访问预览网址时,他只能看到一张图片,例如http://example.com/a.jpg只能打开a.jpg ,而不能同时打开b.jpg 。唯一的选择是创建一个大图像并复制要在预览中显示的pdf页面。我不确定,但是您可以尝试以下代码

$startPage  = 0; // from where to start
$countPages = 1; // how many pages

$pdf = '/pdf/mypdf.pdf[' . $startPage .'-'. $countPages . ']';

$image = new Imagick($pdf);
$image->resizeImage( 400, (($countPages-$startPage)+1)*400, imagick::FILTER_LANCZOS, 0);
$image->setImageFormat( "jpg" );

header('Content-Type: image/jpeg');
echo $im;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM