将gif添加到更大的背景
-
12-12-2019 - |
题
我正在使用imagemagick调整上传的文件大小,但是在处理时,我想向用户显示旋转的GIF轮,缩略图通常是。我为大约7种尺寸的拇指提供服务,并希望车轮保持在中间的32x32尺寸,这是简单的位。
我需要知道的是,我可以在上面做到的同时仍然保留动画
示例:
这张图片:
从这个尺寸开始
与动画
解决方案
PHP女巫有一个解决方案我用来水印GIF动画图像.... 它创建一个黑色的bacground放在它上,然后放水印...
watermarkpath = 'path to wathermarkimage.jpg|gif|png';
$imagepath= 'path to the image';
$watermark = new Imagick($watermarkpath);
$GIF = new Imagick();
$GIF->setFormat("gif");
$animation = new Imagick($imagepath);
foreach ($animation as $frame) {
$iWidth = $frame->getImageWidth();
$iHeight = $frame->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();
}
$bgframe = new Imagick();
$bgframe->newImage(($iWidth), ($iHeight + 80), new ImagickPixel('Black'));
$bgframe->setImageDelay($frame->getImageDelay());
$x = ($iWidth) - $wWidth - 5;
$y = ($iHeight + 80) - $wHeight - 5;
$bgframe->compositeImage($frame, imagick::COMPOSITE_DEFAULT, 0, 0);
$bgframe->flattenImages();
$bgframe->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
$bgframe->flattenImages();
$GIF->addImage($bgframe);
}
$GIF->writeimages($imagepath,true);
. 其他提示
签出这个小提琴,它可能包含你想要的东西: http://jsfiddle.net/tgdfb/1/
它使用jquery,但应该很容易适应...
最终通过Photoshop手动做到这一点,在无法找到通过ImageMagick进行自动执行此操作的自动操作方式。我发现了“Coalesce”国旗,但并不别的。
不隶属于 StackOverflow