简体   繁体   中英

PHP ImageMagick change color in every frame Animated Gif

I am trying to change RGB values in an animated GIF to another RGB value. However in all my attempts it's only changing the color in one frame instead of all frames.

$imgif = new Imagick(HOME_PATH.'/images/6.gif');
$target = 'rgba(238,131,41, 1.0)';
$fill = 'rgba(163,145,144, 1.0)';
$fuzz = 0.05 * $imgif->getQuantumRange()['quantumRangeLong'];
$imgif->opaquePaintImage($target, $fill, $fuzz, false, Imagick::CHANNEL_DEFAULT);

$imgifblob = $imgif->getImagesBlob();

Is there anyway to index a color for the entire GIF and change it? I am rather lost as I don't have much experience with image manipulation.

Sorry, I do not know Imagick that well. But here is how to do it in Imagemagick command line. You may have to loop over each frame in Imagick, since it may not allow for multi-frame images to be processing. But perhaps using readImages would work. See https://www.php.net/manual/en/imagick.readimages.php , where you specify all frames in the gif as 6.gif[0--1], which is all frames from frame 0 to the last frame -1. Sorry, I just do not know. An Imagick expert might be able to help further.

Input:

在此处输入图片说明

convert bunny_anim.gif -coalesce -fuzz 10% -fill red -opaque "rgb(51,77,204)" -layers optimize new_bunny.gif


在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM