Hi all, I've been racking my brain the last few days trying to get this to work and keep running into problems. I'm try to convert an animate gif to a 8-bit grayscale format with a custom color mapping. Essentially the grayscale file is every frame of the animated gif converted to the custom 8-bit mapping, and each frame is just appended to the previous one.
I'm able to do a standard grayscale conversion to get my basic output using:
convert out.gif -append out.gray
However this uses the standard grayscale intensity settings to convert which isn't what I need. However it does convert all the frames of the animated gif and append them to the output file correctly.
Since I need a custom color mapping, I'm using the -fx operator to do this.
convert out.gif -fx "((b*256)&224)/256 + ((g*256)&224)/2048) + ((r*256)&192)/16384)" -append out.gray
However, this only converts the very first frame of the animated gif. How can I do this to convert all frames of the gif?
Any thoughts?
Thanks,
Ken
Converting an animated gif to a custom grayscale image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting an animated gif to a custom grayscale image
try adding -coalesce
Code: Select all
convert out.gif -coalesce -fx "((b*256)&224)/256 + ((g*256)&224)/2048) + ((r*256)&192)/16384)" -append out.gray
Re: Converting an animated gif to a custom grayscale image
Thanks - I've tried to add -coalesce but it's still the same output and didn't fix the issue, it just gives the first frame from the animated gif.
Thanks,
Ken
Thanks,
Ken
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting an animated gif to a custom grayscale image
Yes, -fx only works on the first image in the command line, unless you reference each by u[...]. But I do not think that helps here.
But you can do this loop. Unix syntax.
But you can do this loop. Unix syntax.
Code: Select all
num=`convert anim.gif -coalesce -format "%s\n" info: | tail -n 1`
echo $num
for ((i=0; i<=num; i++)); do
convert anim.gif[$i] -fx "((b*256)&224)/256 + ((g*256)&224)/2048) + ((r*256)&192)/16384)" miff:-
done | convert - +append out.png
Re: Converting an animated gif to a custom grayscale image
Thanks - I was able to get it to work using a shell script like you showed.
Thanks!
Ken
Thanks!
Ken