略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::getNumberImages

2024-11-13

Imagick::getNumberImages

(PECL imagick 2, PECL imagick 3)

Imagick::getNumberImagesReturns the number of images in the object

说明

public Imagick::getNumberImages(): int

Returns the number of images associated with Imagick object.

参数

此函数没有参数。

返回值

Returns the number of images associated with Imagick object.

错误/异常

错误时抛出 ImagickException。

add a noteadd a note

User Contributed Notes 2 notes

up
3
benkuhl at gmail dot com
9 years ago
For PDFs this function indicates the number of pages on the PDF, NOT images that might be embedded within the PDF.

<?php

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

var_dump($document->getNumberImages()); //returns 2

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

var_dump($document->getNumberImages()); //returns 1

?>

From my research it is not possible to obtain the images embedded within a PDF by using the PHP Imagick library.
up
2
gzabriskie at yahoo dot com
13 years ago
<?php
/* Create the object */
$image = new Imagick('YourImageLocation.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->previousImage();
 
$image->thumbnailImage( 400, null );
 
$image->writeImage('img'.$count.'.png');
 
$count--;
}
?>

<html>
  <head>
    <title>Extracting Images Form 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\">image $x (png)</p></td>";
      }
     
?>
    </tr></table>
  </body>
</html>

官方地址:https://www.php.net/manual/en/imagick.getnumberimages.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3