Shadow for transparent animated gif

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?".
yakobom
Posts: 27
Joined: 2015-10-27T22:40:37-07:00
Authentication code: 1151

Re: Shadow for transparent animated gif

Post by yakobom »

Hi,
One more thing - when I use the code you've posted with another gif I get a very weird behavior - flickering and offset. What can be the problem with that?
Original image:
Image

My result:
Image

The code:

Code: Select all

convert http://www.broadheath.coventry.sch.uk/wp-content/uploads/2013/09/superman1.gif -coalesce -write mpr:img -delete 0--1 \( mpr:img -gravity northwest -extent 200x200% \) null: \( mpr:img -background '#5E5E59' -shadow 55x12-20-10  -flip -virtual-pixel Transparent +distort SRT "%w,%h 0.75,0.25 0 %[fx:1.25*w],%[fx:1.25*h]" \) -background transparent -layers composite -trim +repage animation.gif
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Shadow for transparent animated gif

Post by dlemstra »

What is your version of ImageMagick and your operating system?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
yakobom
Posts: 27
Joined: 2015-10-27T22:40:37-07:00
Authentication code: 1151

Re: Shadow for transparent animated gif

Post by yakobom »

I am using version 6.9.2-5 which I have built on Ubuntu 14.04
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Shadow for transparent animated gif

Post by snibgo »

In Fred's example, objects near the frame edges didn't move, so the final "-trim" removed the same from each frame.

If you want to crop, you should crop the same amount from each frame.
snibgo's IM pages: im.snibgo.com
yakobom
Posts: 27
Joined: 2015-10-27T22:40:37-07:00
Authentication code: 1151

Re: Shadow for transparent animated gif

Post by yakobom »

So you are saying that removing the '-trim' should give me a bigger but working gif? I've tried it, it looks pretty much the same (the size does not change, but the black background and flickering remains)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Shadow for transparent animated gif

Post by snibgo »

"-background None" in the first mpr cures the background opacity. Windows BAT syntax:

Code: Select all

convert ^
  superman1.gif ^
  -coalesce -write mpr:img ^
  -delete 0--1 ^
  ( mpr:img -gravity northwest -background None -extent 200x200%% ) ^
  null: ^
  ( mpr:img -background #5E5E59 -shadow 55x12-20-10  -flip ^
    -virtual-pixel Transparent ^
    +distort SRT "%%w,%%h 0.75,0.25 0 %%[fx:1.25*w],%%[fx:1.25*h]" ^
  ) ^
  -background Transparent ^
  -layers composite ^
  t1.gif
snibgo's IM pages: im.snibgo.com
yakobom
Posts: 27
Joined: 2015-10-27T22:40:37-07:00
Authentication code: 1151

Re: Shadow for transparent animated gif

Post by yakobom »

Thanks a lot guys, this is really helpful.
One more thing I've noticed - following Fred's earlier suggestion for softening the shadow, I tried adding

Code: Select all

'-background white -compose over -flatten'
However if I put it at the end, the animation stops and it becomes a regular image... Where exactly should I put it in order to keep the animation?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Shadow for transparent animated gif

Post by fmw42 »

Sorry, my mistake. I wanted to flatten each frame.

See snibgo's suggestion above about adding -background none. Here is his command in Unix syntax

Code: Select all

convert http://www.broadheath.coventry.sch.uk/wp-content/uploads/2013/09/superman1.gif \
-coalesce -write mpr:img -delete 0--1 \
\( mpr:img -gravity northwest -background None -extent 200x200% \) \
null: \
\( mpr:img -background '#5E5E59' -shadow 55x12-20-10  -flip -virtual-pixel \
Transparent +distort SRT "%w,%h 0.75,0.25 0 %[fx:1.25*w],%[fx:1.25*h]" \) \
-background transparent -layers composite -trim +repage animation.gif
yakobom
Posts: 27
Joined: 2015-10-27T22:40:37-07:00
Authentication code: 1151

Re: Shadow for transparent animated gif

Post by yakobom »

Thanks, but I am still missing the way to flatten each frame - can you please help me with that as well?
Many thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Shadow for transparent animated gif

Post by fmw42 »

Same way, just use -background white before the -extent (or some other color, whatever you want)

Code: Select all

convert http://orig08.deviantart.net/03fe/f/2013/037/f/d/cry__poke_by_kiwa007-d5u29cm.gif \
-coalesce -write mpr:img -delete 0--1 \( mpr:img -gravity northwest -background white -extent 200x200% \) \
null: \( mpr:img -background '#5E5E59' -shadow 55x12-20-10  \
-flip -virtual-pixel Transparent +distort SRT "%w,%h 0.75,0.25 0 %[fx:1.1*w],%[fx:0.90*h]" \) \
-background transparent -layers composite -trim +repage animation2.gif
Image
yakobom
Posts: 27
Joined: 2015-10-27T22:40:37-07:00
Authentication code: 1151

Re: Shadow for transparent animated gif

Post by yakobom »

Great - I got all I needed. Thanks for the great support.
Arise
Posts: 3
Joined: 2016-09-13T03:56:59-07:00
Authentication code: 1151

Re: Shadow for transparent animated gif

Post by Arise »

I'm trying to add some shadow coming from front/left side lets say...
I've tried all kind of parameters/values but every time the shadow cast is not properly positioned starting at the feet and is badly skewed.
Also, the final image is not maintained at 256x256.

I tried with understanding the previous posts, I've arrived at affine transformations and now I'm stuck... after like 3 days of trying to understand what is going on.

Code: Select all

convert 1.png ^
	-flip +distort SRT "0,0 1,-1 0" ^
          ( +clone -background #5E5E59 -shadow 60x5+0+0 ^
             -virtual-pixel Transparent ^
			+distort Affine "0,256 0,256      0,256  0,256       128,128  128,124 "^
          ) +swap -background Transparent -layers merge ^
          -fuzz 2%% standing_shadow.png
The image I'm using:
Image
Post Reply