PHP ImageMagick是否有办法将页面数计入TIF图像文件中,而无需加载完整的文件?

发布于 2025-01-21 05:35:30 字数 1063 浏览 5 评论 0原文

让我描述场景。

Environemnt :Redhat Linux 7.9 + ImageMagick* + PECL Imagick + PHP脚本。

范围:必须允许进入GUI应用程序用户从多TIF文件中查看单个图像。

文件: Multi-Tiff文件被jpeg压缩。

问题: 我有包含n张图像的TIF文件,总尺寸从几个MB到1/2GB,我需要以两种方式访问​​它们:

  1. [ ko ]需求计算图像的总数包含在tif中的图像。

    $ img = new Imagick($ filename); $ img-> getnumberimages();

    使用这种访​​问方式,PHP类需要很长的时间将TIF加载〜2612张图像,约498m,如15秒。(未压缩的TIF约为1.3G)。

  2. [ ok ] 访问#n image 进入TIF,以允许用户查看每个单个图像。

    $ img = new Imagick($ filename。“ [1]”); $ img-> setImageFormat(“ jpeg”);> $ thumbnail = $ img-> getImageBlob();

    它是' ok '

**两个点1/2均通过不同的Imagick库版本进行了测试:6.7.8-9,6.9.10-68 Q16,7.1.0(Q16 HDRI)[pecl Imagick 3.4或3.7] + GraphicsMagick-1.3.36,但是没有有意义的区别。

是否可以将图像的数量纳入TIF,而无需使用时间以 Imagick PHP类初始化完整的TIF ?

let me describe the scenario.

Environemnt: RedHat linux 7.9 + ImageMagick* + pecl imagick + PHP script.

Scope: Into GUI application user must be allowed to see the single images from a multi-TIF file.

File: multi-tiff file are JPEG compressed.

Problem:
I have TIF file that contains N images, total size from few MB to 1/2GB and I need to access to them in two way much faster as possible:

  1. [KO] Need to count the total number of images contained into TIF.

    $img = new Imagick($filename); $img->getNumberImages();

    With this way of access, the php class takes quite long time to load a TIF with ~2612 images,about 498M, like 15 seconds.(uncompressed tif is about 1.3G).

  2. [OK] Access to the #n image into TIF to allow the user to see each single image.

    $img = new Imagick($filename."[1]");$img->setImageFormat("jpeg");
    $thumbnail = $img->getImageBlob();

    It is 'OK' because the speed is high for the scope (always less than (and far from) 1 second)

** Both point 1/2 was tested with different imagick library version: 6.7.8-9, 6.9.10-68 Q16, 7.1.0 (Q16 HDRI) [pecl imagick 3.4 or 3.7] + GraphicsMagick-1.3.36, but there aren't a meaningful difference.

Is there an alternative to get the number of images into TIF without using time to initialize the full tif with Imagick php class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2025-01-28 05:35:30

我意识到您要求您进行ImageMagick,但是 php-vips 可以很快这样做。我尝试了:

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;

if(count($argv) != 4) {
    echo("usage: ./page.php input-image output-image page-number\n");
    exit(1);
}

// open and check the number of pages
$image = Vips\Image::newFromFile($argv[1]);
$n_pages = $image->get("n-pages");
echo("image $argv[1] has $n_pages pages\n" );

// grab a specific page
$page = Vips\Image::newFromFile($argv[1], ["page" => intval($argv[3])]);
echo("page $argv[3] is {$page->width} by {$page->height} pixels\n" );

// thumbnail the page to 500 pixels across and save as jpg
echo("thumbnailing ...\n");
// this is needed in current libvips to stop thrashing during thumbnail,
// it'll be unnecessary in 8.13+
$page = $page->sequential([
    "tile_height" => 128
]);
$thumb = $page->thumbnail_image(500);
$thumb->writeToFile($argv[2]);
echo("done\n");

我看到:

$ ls -l ~/pics/sample/x.tif
-rw-rw-r-- 1 john john 1471953608 Apr 14 09:31 /home/john/pics/sample/x.tif
$ time ./page.php ~/pics/sample/x.tif x.jpg 1234
image /home/john/pics/sample/x.tif has 2600 pages
page 1234 is 2900 by 2048 pixels
thumbnailing ...
done

real    0m0.296s
user    0m0.439s
sys 0m0.063s

因此,使用1.4GB,2600页tiff,它可以在300毫秒内获取和缩略图。

I realize you asked for imagemagick, but php-vips can do this pretty quickly. I tried:

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;

if(count($argv) != 4) {
    echo("usage: ./page.php input-image output-image page-number\n");
    exit(1);
}

// open and check the number of pages
$image = Vips\Image::newFromFile($argv[1]);
$n_pages = $image->get("n-pages");
echo("image $argv[1] has $n_pages pages\n" );

// grab a specific page
$page = Vips\Image::newFromFile($argv[1], ["page" => intval($argv[3])]);
echo("page $argv[3] is {$page->width} by {$page->height} pixels\n" );

// thumbnail the page to 500 pixels across and save as jpg
echo("thumbnailing ...\n");
// this is needed in current libvips to stop thrashing during thumbnail,
// it'll be unnecessary in 8.13+
$page = $page->sequential([
    "tile_height" => 128
]);
$thumb = $page->thumbnail_image(500);
$thumb->writeToFile($argv[2]);
echo("done\n");

I see:

$ ls -l ~/pics/sample/x.tif
-rw-rw-r-- 1 john john 1471953608 Apr 14 09:31 /home/john/pics/sample/x.tif
$ time ./page.php ~/pics/sample/x.tif x.jpg 1234
image /home/john/pics/sample/x.tif has 2600 pages
page 1234 is 2900 by 2048 pixels
thumbnailing ...
done

real    0m0.296s
user    0m0.439s
sys 0m0.063s

So with a 1.4gb, 2600 page TIFF it can fetch and thumbnail a page in about 300ms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文