Appending PNG to animated image

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
Essem
Posts: 4
Joined: 2020-02-06T12:13:22-07:00
Authentication code: 1152

Appending PNG to animated image

Post by Essem »

Hello,
I am trying to append an image containing some text onto an animated GIF using ImageMagick 6.9.7-4 on Ubuntu 18.04, as per this thread. However, I'm trying to do it the opposite way, like this:

Image

I changed GeeMack's command in the original thread to this:

Code: Select all

convert \( border.gif -coalesce \) -alpha set -background black text.png -set page "%[fx:v.w]x%[fx:u.h+v.h]+[fx:t?(v.w-u.w)/2:0]+%[fx:t?v.h:0]" -coalesce null: -insert 1 -layers composite -layers optimize output2.gif
However, this command does not produce the expected result. Here's what it outputs:
Image

Here are my input images for reference:
Image

Image

Thanks in advance.

snibgo
Posts: 12932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Appending PNG to animated image

Post by snibgo »

"null: -insert 1" creates a null image, and moves it to position 1 in the list, ie the second image. That was good for the png + gif_frames problem. But for the gif_frames + png problem, the null should go near the end, not the start. Change "-insert 1" to "+swap".

The "-set page" may also be wrong.
snibgo's IM pages: im.snibgo.com

Essem
Posts: 4
Joined: 2020-02-06T12:13:22-07:00
Authentication code: 1152

Re: Appending PNG to animated image

Post by Essem »

snibgo wrote:
2020-02-06T16:52:24-07:00
"null: -insert 1" creates a null image, and moves it to position 1 in the list, ie the second image. That was good for the png + gif_frames problem. But for the gif_frames + png problem, the null should go near the end, not the start. Change "-insert 1" to "+swap".

The "-set page" may also be wrong.
Alright, I changed it and got this:
Image

I did change the "-set page" in the original command to swap many of the values, however that seems to have not worked.

snibgo
Posts: 12932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Appending PNG to animated image

Post by snibgo »

I would do it like this (Windows BAT script):

Code: Select all

magick ^
  border2.gif -layers coalesce ^
  -extent 600x670 ^
  null: ^
  ( text.png -set page +0+591 ) ^
  -layers composite ^
  -layers optimize ^
  out.gif
snibgo's IM pages: im.snibgo.com

Essem
Posts: 4
Joined: 2020-02-06T12:13:22-07:00
Authentication code: 1152

Re: Appending PNG to animated image

Post by Essem »

snibgo wrote:
2020-02-06T19:32:39-07:00
I would do it like this (Windows BAT script):

Code: Select all

magick ^
  border2.gif -layers coalesce ^
  -extent 600x670 ^
  null: ^
  ( text.png -set page +0+591 ) ^
  -layers composite ^
  -layers optimize ^
  out.gif
Sorry I didn't mention this earlier, but I also want it to work with nearly any GIF that I use as input. These GIFs would vary in size, but the text image would be automatically generated to accommodate for that size. Because of this, simply adjusting by a static size wouldn't work.

snibgo
Posts: 12932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Appending PNG to animated image

Post by snibgo »

Essem wrote:... but the text image would be automatically generated to accommodate for that size.
So your script knows how large the GIF and text images are. Those dimensions can be put into environment variables. So you can use %[fx:...] expressions for the "-extent" and "-set page".
snibgo's IM pages: im.snibgo.com

Essem
Posts: 4
Joined: 2020-02-06T12:13:22-07:00
Authentication code: 1152

Re: Appending PNG to animated image

Post by Essem »

snibgo wrote:
2020-02-07T09:38:22-07:00
Essem wrote:... but the text image would be automatically generated to accommodate for that size.
So your script knows how large the GIF and text images are. Those dimensions can be put into environment variables. So you can use %[fx:...] expressions for the "-extent" and "-set page".
Since I am using ImageMagick 6, fx doesn't work for -extent, so I had to work around that. Other than that, it did the trick. Thanks for the help!

Post Reply