2016-08-08 82 views
1

我需要使用imageMagick爲動畫GIF添加水印。
但我有一個問題!

我的代碼:
使用imageMagick將水印添加到動畫GIF(PHP)

<?php 
$image = new Imagick(); 
$image->readImage("orginal.gif"); 

$watermark = new Imagick(); 
$watermark->readImage("watermark.png"); 

// how big are the images? 
$iWidth = $image->getImageWidth(); 
$iHeight = $image->getImageHeight(); 
$wWidth = $watermark->getImageWidth(); 
$wHeight = $watermark->getImageHeight(); 

if ($iHeight < $wHeight || $iWidth < $wWidth) { 
// resize the watermark 
$watermark->scaleImage($iWidth, $iHeight); 

// get new size 
$wWidth = $watermark->getImageWidth(); 
$wHeight = $watermark->getImageHeight(); 
} 

// calculate the position 
$x = ($iWidth - $wWidth)/2; 
$y = ($iHeight - $wHeight)/2; 

$image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y); 

header("Content-Type: image/" . $image->getImageFormat()); 
echo $image; 
?> 

原始GIF:
See Original GIF

輸出GIF:
See Output GIF

創建水印後,我的GIF不是動畫!
我該如何解決它?

+1

您需要合併圖像並將水印應用到每個框架,然後重新組裝http://php.net/manual/en/imagick.coalesceimages.php –

回答

1

您剛剛發現了一些代碼來爲圖像加水印。有了動畫,你需要分離每一幀,將其水印並重新放在一起。檢出:coalesce

+0

Snap !!!!!!! !!!! –

+1

偉大的思想家都認爲 – Bonzo