PHP Conference Japan 2024

Imagick::coalesceImages

(PECL imagick 2, PECL imagick 3)

Imagick::coalesceImages合成一組影像

說明

public Imagick::coalesceImages(): Imagick

合成一組影像,同時考慮任何頁面偏移和處置方法。GIF、MIFF 和 MNG 動畫序列通常以影像背景開始,而每個後續影像的大小和偏移量都不同。傳回一個新的 Imagick 物件,其中序列中的每個影像都與第一個影像大小相同,並與序列中的下一個影像合成。

參數

此函數沒有參數。

傳回值

成功時傳回新的 Imagick 物件。

錯誤/例外

發生錯誤時拋出 ImagickException。

新增註解

使用者貢獻的註解 3 則註解

ktr
12 年前
調整大小和/或裁切動畫 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_h, 0, 0);
}

$image = $image->deconstructImages();
$image->writeImages($file_dst, true);
?>
vikomic at gmail dot com
13 年前
這是一個如何調整 GIF 大小的範例。

<?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);

// 可以新增更多 gif
$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();
?>

您可以使用此範例中的任何調整大小方法(resizeImage)。

此範例在 *imagick 模組版本 2.2.1-dev* 中運作正常,但在 *imagick 模組版本 3.0.1* 中運作不正確。
Anony
8 年前
如果您想要開啟動畫 gif,請不要使用 $imagick->pingImage() 來 ping 影像,您會得到與 gif 中相同的影格數量,新增到開頭 - 但它們都是帶條紋的黑色。所以您的影格數量是 gif 實際影格數量的兩倍。
To Top