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(120, 120, Imagick::FILTER_BOX, 1);
} while ($imagick->nextImage());
$imagick = $imagick->deconstructImages();
$imagick->writeImages('new_120x120.gif', true);
// can be added some more gifs
$imagick = $imagick->coalesceImages();
do {
$imagick->resizeImage(100, 100, Imagick::FILTER_BOX, 1);
} 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*.
Imagick::coalesceImages
(PECL imagick 2.0.0)
Imagick::coalesceImages — 複数の画像を合成する
説明
ページオフセットや処理方法を指定して、複数の画像を合成します。 典型的な使用例としては、たとえば GIF や MIFF、MNG といった画像シーケンスを最初に背景として指定し、 それ以降にさまざまなサイズやオフセットの画像を合成するというものがあります。 返り値は、新規 Imagick オブジェクトとなります。 シーケンスの各画像のサイズは、最初の画像のサイズと同じになります。
返り値
成功した場合に新規 Imagick オブジェクトを返します。
エラー / 例外
エラー時に ImagickException をスローします。
vikomic at gmail dot com
02-May-2011 03:58
