文字

Imagick::coalesceImages

(PECL imagick 2.0.0)

Imagick::coalesceImagesComposites a set of images

说明

Imagick Imagick::coalesceImages ( void )

Composites a set of images while respecting any page offsets and disposal methods. GIF, MIFF, and MNG animation sequences typically start with an image background and each subsequent image varies in size and offset. Returns a new Imagick object where each image in the sequence is the same size as the first and composited with the next image in the sequence.

返回值

Returns a new Imagick object on success.

错误/异常

错误时抛出 ImagickException。

用户评论:

[#1] dikirill [2013-03-08 16:51:21]

I tried examples below, and couldn't make them work. And found that version of my php-imagick extension is 3.1.0RC1, and looks like it's buggy in function "writeImages", downgrade to 3.0.1 helped me.

[#2] ktr [2012-10-17 20:06:50]

resize and/or crop an animated GIF

<?php
$image 
= new Imagick($file_src);

$image $image->coalesceImages();

foreach (
$image as $frame) {
  
$frame->cropImage($crop_w$crop_h$crop_x$crop_y);
  
$frame->thumbnailImage($size_w$size_h);
  
$frame->setImagePage($size_w$size_h00);
}

$image $image->deconstructImages();
$image->writeImages($file_dsttrue);
?>

[#3] vikomic at gmail dot com [2011-05-02 03:58:26]

Here goes an exaple how to resize GIF-s.

<?php
$imagick 
= new Imagick("original.gif");

$format $imagick->getImageFormat();
if (
$format == 'GIF') {
  
$imagick $imagick->coalesceImages();
  do {
     
$imagick->resizeImage(120120Imagick::FILTER_BOX1);
  } while (
$imagick->nextImage());
  
$imagick $imagick->deconstructImages();
  
$imagick->writeImages('new_120x120.gif'true);

  
// can be added some more gifs
  
$imagick $imagick->coalesceImages();
  do {
     
$imagick->resizeImage(100100Imagick::FILTER_BOX1);
  } while (
$imagick->nextImage());
  
$imagick $imagick->deconstructImages();
  
$imagick->writeImages('new_100x100.gif'true);
}

$imagick->clear();
$imagick->destroy();
?>


You can use any resize method (resizeImage) with this example.

This example works fine with *imagick module version 2.2.1-dev*, but doesn't work correctly with *imagick module version 3.0.1*.

上一篇: 下一篇: