繁体   English   中英

PHP imagick从Tiff获取所有图像

[英]PHP imagick get all images from tiff

我正在尝试加载tiff文件并计算数量或图像,然后将每个图像显示为PNG缩略图。

计数部分是好的,它计数6(这是该tif中的正确页数),然后代码列出同一图像的6,这是tiff的第一页。 如果我的循环出现问题,或者我根本没有正确使用imagick函数,则无法进行锻炼。

谁能帮忙

<?php

$image2 = new Imagick('http://mysite.org.uk/tiftest/2.tif'); 


/* Create the object */
$image = new Imagick('http://mysite.org.uk/tiftest/2.tif');
$count = $image->getNumberImages();

echo "<h3 style=\"font: bold 12pt Arial\">Total Number of Images Extracted ".
 "from the TIF : ".$image->getNumberImages()."</h3>";

for ($x = 1;$x <= $image->getNumberImages();$x++) {
    $image->pingImage( $image2 );    
    $image->readImageFile( $image2 );    
    $image->setImageFormat( 'png' );
    $image->thumbnailImage(100, 0);
echo "<img id='" . $x . "' src='data:image/png;base64,".base64_encode($image)."' />"; } ?>

您将必须使用$image->previousImage()移至上一张图像。

向后遍历图像数量并移至上一个图像以获取所有图像,也许还可以使用while ($image->hasPreviousImage()) {}构造

哦,不要使用readImageFile,您已经在内存中保存了图像。

我怀疑了!

这是将所有独立页面从tif中取出并显示为PNG的代码:

<?php
/* Create the object */
$image = new Imagick('http://mysite.o.uk/tiftest/1.tif');
$count = $image->getNumberImages();

echo "<h3 style=\"font: bold 12pt Arial\">Total Number of Images Extracted ".
  "from the TIF : ".$image->getNumberImages()."</h3>";
 $x =0;

foreach ( $image as $image ) {  
    $x++;
    $image->setImageFormat( 'png' );
    $image->thumbnailImage(150, 120);

    echo "<img id='" . $x . "' src='data:image/png;base64,".base64_encode($image)."' />";


 }
?>

但是,现在我需要知道如何在不使用base63编码的情况下将它们显示为真正的PNG,这是什么想法?

暂无
暂无

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

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