PHP Conference Japan 2024

Imagick::getNumberImages

(PECL imagick 2, PECL imagick 3)

Imagick::getNumberImages傳回物件中的圖片數量

描述

public Imagick::getNumberImages(): int

傳回與 Imagick 物件相關聯的圖片數量。

參數

此函式沒有參數。

傳回值

傳回與 Imagick 物件相關聯的圖片數量。

錯誤/例外

發生錯誤時拋出 ImagickException。

新增筆記

使用者貢獻的筆記 2 則筆記

gzabriskie at yahoo dot com
15 年前
<?php
/* 建立物件 */
$image = new Imagick('YourImageLocation.tif');
$count = $image->getNumberImages();

echo
"<h3 style=\"font: bold 12pt Arial\">從 TIF 擷取的圖片總數 ".
":".$image->getNumberImages()."</h3>";

for (
$x = 1;$x <= $image->getNumberImages(); $x++) {
$image->previousImage();
$image->thumbnailImage( 400, null );
$image->writeImage('img'.$count.'.png');
$count--;
}
?>

<html>
<head>
<title>從 TIFF 擷取圖片</title>
</head>
<body>
<table cellspacing="10" style="background: #ddd"><tr>
<?php
for ($x = 1;$x <= $image->getNumberImages(); $x++) {
echo
"<td><img src=\"img$x.png\"<br /><p style=\"font: bold 12pt Arial;".
"text-align: center\">圖片 $x (png)</p></td>";
}
?>
</tr></table>
</body>
</html>
benkuhl at gmail dot com
11 年前
對於 PDF 而言,此函式表示 PDF 上的頁數,而不是 PDF 內可能嵌入的圖片。

<?php

$document
= new Imagick('2_pager.pdf');

var_dump($document->getNumberImages()); //傳回 2

$document = new Imagick('1_pager.pdf');

var_dump($document->getNumberImages()); //傳回 1

?>

根據我的研究,無法使用 PHP Imagick 函式庫取得 PDF 內嵌入的圖片。
To Top