Imagick::appendImages()
(PECL imagick 2.0.0)
Append a set of images
说明
Imagick::appendImages(bool $stack): Imagick
Append a set of images into one larger image.
参数
- $stack
Whether to stack the images vertically. By default(or if
FALSEis specified)images are stacked left-to-right. If$stackisTRUE, images are stacked top-to-bottom.
返回值
Returns Imagick instance on success.
错误/异常
错误时抛出 ImagickException。
范例
Example #1 Imagick::appendImages() example
<?php
/* Create new imagick object */
$im = new Imagick();
/* create red, green and blue images */
$im->newImage(100, 50, "red");
$im->newImage(100, 50, "green");
$im->newImage(100, 50, "blue");
/* Append the images into one */
$im->resetIterator();
$combined = $im->appendImages(true);
/* Output the image */
$combined->setImageFormat("png");
header("Content-Type: image/png");
echo $combined;
?>
以上例程的输出类似于:

# How to combine a multi-page pdf file into a single long image:
<?php
$im1 = new Imagick();
$im1->readImage('multi-page-pdf.pdf');
$im1->resetIterator();
# Combine multiple images into one, stacked vertically.
$ima = $im1->appendImages(true);
$ima->setImageFormat("png");
header("Content-Type: image/png");
echo $ima;
?>
# change $ima to $ima->getimagesblob()
<?php
$im1 = new Imagick();
$im1->readImage('multi-page-pdf.pdf');
$im1->resetIterator();
# Combine multiple images into one, stacked vertically.
$ima = $im1->appendImages(true);
$ima->setImageFormat("png");
header("Content-Type: image/png");
echo $ima->getimagesblob();
?>
Sometimes when running this code on a long running apache24 instance on a server with minimal memory the final "echo $ima;" returns an empty string. Doing an "apache graceful" seems to clear this up. There appears to be no other way to correct OR DETECT this problem. Suckky.
