Attempting to merge a .gif and failing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
stockton
Posts: 9
Joined: 2016-02-27T03:29:27-07:00
Authentication code: 1151
Location: South Africa

Attempting to merge a .gif and failing

Post by stockton »

I have two images, one .png and the 2nd .gif.
I wish to place the gif onto the png and have successfully achieved that using

Code: Select all

convert DEVACSST.png -page +370+105 stlogorotating.gif index.gif
however even though the gif apparently has a transparent background it is not transparent in the image at http://devacs.za.net/index.gif so I attempted

Code: Select all

convert DEVACSST.png -page +370+105 stlogorotating.gif -transparent white index.gif

as well as all values of -fuzz from 2% to 10% all in vain.
So I looked at

Code: Select all

convert index.gif -format %c histogram:info: | head
    314825: (  0,  0,  0,255) #000000 black
      6282: (  0,  0,  0,  0) #00000000 none
       110: (  0,  1, 53,255) #000135 srgba(0,1,53,1)
       882: (  1,  1, 61,255) #01013D srgba(1,1,61,1)
      2280: (  1,  1, 67,255) #010143 srgba(1,1,67,1)
      2212: (  1,  1, 75,255) #01014B srgba(1,1,75,1)
      2283: (  1,  1, 83,255) #010153 srgba(1,1,83,1)
      2379: (  1,  1, 92,255) #01015C srgba(1,1,92,1)
      1362: (  1,  1, 97,255) #010161 srgba(1,1,97,1)
        42: (  2,  1, 18,255) #020112 srgba(2,1,18,1)
which I am afraid means little to me
Then thought that what I should do is alter stlogorotating.gif to transparent background using

Code: Select all

convert stlogorotating.gif -transparent white st.gif
and again all values of -fuzz as before.
Please make suggestions.
stockton
Posts: 9
Joined: 2016-02-27T03:29:27-07:00
Authentication code: 1151
Location: South Africa

Re: Attempting to merge a .gif and failing

Post by stockton »

I forgot to mention that I would also appreciate getting rid of the "hiccup".
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Attempting to merge a .gif and failing

Post by GeeMack »

stockton wrote:I have two images, one .png and the 2nd .gif.
I wish to place the gif onto the png and have successfully achieved that [...] Please make suggestions.
It's always best if you let us know what version of ImageMagick you're using and what OS/platform you're working on.

It's a little difficult to understand exactly what you're trying to do, but it looks like you want the spinning logo inside the seal with the stars. I'm using Windows 7 64 and IM version "ImageMagick 6.9.3-1 Q16 x64 2016-01-17". If my guess is correct, running this command on your "index.gif" seems to give the results you're trying to achieve.

Code: Select all

convert index.gif[0] null: -delay 5 index.gif[1-14] -layers composite -layers optimize output.gif
That puts the first layer of the GIF, "index.gif[0]", on one side of the "null:" image, and the rest of the layers, "index.gif[1-14]", on the other side.

Next the "-layers composite" operator alternates using the images from one side of the "null:" and the other to build your layers by compositing the logo over the background image. It uses the background over and over until the logo images after the "null:' are all used up. At that point you have 15 layers, each with a background and one frame of your animated spinning Star Fleet logo.

If you stop there you'd have an output GIF of around 500kb. So after the images are built with the "-layers composite" operator, I added the "-layers optimize" operator to reduce the finished output size of the GIF. I end up with the logo spinning over the stars seal, transparent backgrounds on the spinners, in a GIF named "output.gif" that weighs only about 75kb.

Additionally, I put a "-delay 5" in there ahead of the spinning images to slow down the animation a bit. It seemed too fast to me.

EDITED TO ADD: I noticed the leaves surrounding the seal were also transparent. If that's not what you want, if you want them to be white, you can flatten that first image onto a white background with something like this...

Code: Select all

convert -background white index.gif[0] -flatten -background none null: -delay 5 index.gif[1-14] -layers composite -layers optimize output.gif
The rest of the command continues pretty much as described above.
stockton
Posts: 9
Joined: 2016-02-27T03:29:27-07:00
Authentication code: 1151
Location: South Africa

Re: Attempting to merge a .gif and failing

Post by stockton »

Sorry that I missed telling you that I am using ImageMagick 6.8.9-9 Q16 i586 2015-01-05 on Debian Jessie Linux system.
DEVACSST.png is the background page and stlogorotating.gif is the animated image I need to apply to the background.
I do not understand where DEVACSST.png fits into your commands or are your commands to make stlogorotating.gif suitable to place on the background?
stockton
Posts: 9
Joined: 2016-02-27T03:29:27-07:00
Authentication code: 1151
Location: South Africa

Re: Attempting to merge a .gif and failing

Post by stockton »

Thank you, you nearly got me there but what I now have is what shows at http://devacs.za.net/index.gif and/or http://devacs.za.net/lcars.html
The background is now transparent but I now need to get rid of the echo.
As you can see I worked out that your commands had nothing to do with DEVACSST.png, sorry for being slow.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Attempting to merge a .gif and failing

Post by GeeMack »

stockton wrote:The background is now transparent but I now need to get rid of the echo.
I think I understand what you're trying to do, but without your original images it's difficult to help you work out a command that gets the whole job done. Maybe you can upload them to your server so we can try a few things.

Meanwhile here's a wild untested guess at a command that might give you some ideas...

Code: Select all

convert DEVACSST.png -background white -flatten -background none \
   null: -delay 5 \( stlogorotating.gif -transparent white \) \
   -geometry +370+105 -layers composite -layers optimize index.gif
Note the backslashes "\" used to escape the newlines and parentheses. I'm not working in *nix, but I think that's pretty close to how you need to do it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Attempting to merge a .gif and failing

Post by snibgo »

stlogorotating.gif may be compressed, and need "-layers coalesce".
snibgo's IM pages: im.snibgo.com
stockton
Posts: 9
Joined: 2016-02-27T03:29:27-07:00
Authentication code: 1151
Location: South Africa

Re: Attempting to merge a .gif and failing

Post by stockton »

I have placed both images on my server. http://devacs.za.net/stlogorotating.gif & http://devacs.za.net/DEVACSST.png.
I hope that that helps.
However if you look at http://devacs.za.net/lcars.html it looks as if you, with your last command, has solved the problem for me. Thank you.
Last edited by stockton on 2016-02-29T02:08:47-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Attempting to merge a .gif and failing

Post by snibgo »

Have you tried GeeMack's "wild untested guess"? It looks perfect to me.
snibgo's IM pages: im.snibgo.com
stockton
Posts: 9
Joined: 2016-02-27T03:29:27-07:00
Authentication code: 1151
Location: South Africa

Re: Attempting to merge a .gif and failing

Post by stockton »

Yes I have and as I said it looks fine to me http://devacs.za.net/lcars.html
Post Reply