Log in

View Full Version : Image dropshadow


MrC
11th September 2008, 08:28
I am trying to add a transparent dropshadow to an image/clip. My sample script is:

Background = BlankClip(width=400,height=400,color=$0000FF)
Image = BlankClip(width=200,height=200,color=$FF0000)
Shadow = BlankClip(width=Image.width,height=Image.width,color=$000000)
Background = Overlay(Background,Shadow,x=105,y=105,mode="blend",opacity=0.5)
Background = Overlay(Background,Image,x=100,y=100,mode="blend",opacity=1)
return Background

The 3D effect is somehow "flat", the shadow does not have the softness I can see, for example, in WinXP tooltips' dropshadows.

Is there any way to improve the script to obtain a better visual effect?

Thanks in advance

:)

Bye

45tripp
11th September 2008, 09:21
play without know

Background = BlankClip(width=400,height=400,color=$0000FF)
Image = BlankClip(width=200,height=200,color=$FF0000)
Shadow = BlankClip(width=Image.width,height=Image.width,color=$000000).blur(1.58)
Background = Overlay(Background,Shadow,x=102,y=102,mode="blend",opacity=0.5).blur(1)
Background = Overlay(Background,Shadow,x=104,y=104,mode="blend",opacity=0.4).blur(1.2)
Background = Overlay(Background,Shadow,x=106,y=106,mode="blend",opacity=0.3).blur(1.58)
Background = Overlay(Background,Image,x=100,y=100,mode="blend",opacity=1).blur(0.5)

return background

look any better?

MrC
11th September 2008, 13:03
Yes, it looks really great, with solid monochromatic rectangles...

But, when using a image background, all that blur ruins the output...

:confused:

Bye

45tripp
11th September 2008, 14:12
oh,
but i'm the monocromatic rectangle type...

this then?

Background = ImageReader("C:\Desktop\traingr4.jpg")#BlankClip(width=400,height=400,color=$0000ff)
Image = BlankClip(width=200,height=200,color=$FF0000)
Shadow = BlankClip(width=Image.width,height=Image.width,color=$000000)

Background = Overlay(Background,Shadow,x=101,y=101,mode="blend",opacity=0.4)
Background = Overlay(Background,Shadow,x=102,y=102,mode="blend",opacity=0.4)
Background = Overlay(Background,Shadow,x=103,y=103,mode="blend",opacity=0.3)
Background = Overlay(Background,Shadow,x=104,y=104,mode="blend",opacity=0.2)
Background = Overlay(Background,Shadow,x=105,y=105,mode="blend",opacity=0.2)
Background = Overlay(Background,Shadow,x=106,y=106,mode="blend",opacity=0.1)
Background = Overlay(Background,Shadow,x=107,y=107,mode="blend",opacity=0.1)

Background = Overlay(Background,Image,x=100,y=100,mode="blend",opacity=1)

return background

mikeytown2
12th September 2008, 01:20
Made this into a fairly simple function, with no error checking. Any Chance of making a for loop or a recursive function?


Background = ColorBars(640,480).Trim(0,239)
Image = BlankClip(pixel_type="YUY2").ColorYUV(showyuv=true).BilinearResize(320,240).Trim(0,239)

DropShadow(Background, Image)

Function DropShadow(clip Background, clip Overlayed)
{
#Set Defaluts
CenterX = Round(width(Background)/2.0 - width(Overlayed)/2.0)
CenterY = Round(height(Background)/2.0 - height(Overlayed)/2.0)
Shadow = BlankClip(width=width(Overlayed),height=height(Overlayed),color=$000000)
StartOpacity = 0.4
Steps = 8
CountDown = Float(Steps)
CountUp = 1

#for loop would be nice right here
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0
Background = Overlay(Background,Shadow,x=CenterX+CountUp,y=CenterY+CountUp,mode="blend",opacity=StartOpacity*(CountDown/Steps))
CountUp = CountUp+1
CountDown = CountDown-1.0



Background = Overlay(Background,Overlayed,x=CenterX,y=CenterY,mode="blend",opacity=1)

return background
}


Being able to set the drop shadow and adding an align would be nice features to add in the future.

tin3tin
12th September 2008, 10:55
Any Chance of making a for loop or a recursive function?

Take a look at this: http://forum.doom9.org/showthread.php?p=367841#post367841

MrC
12th September 2008, 12:47
@45tripp, mikeytown2

Great job! Thanks a lot!

:thanks:

Bye

Gavino
12th September 2008, 22:28
Any Chance of making a for loop or a recursive function?
How about this auxiliary function:

function AddShadows(clip background, clip shadow, int x, int y, float opacity, int steps) {
background = Overlay(background, shadow, x=x+1, y=y+1, mode="blend", opacity=opacity)
steps > 1 ? AddShadows(background, shadow, x+1, y+1, opacity*(steps-1)/steps, steps-1) : background
}
Then you could replace the 8 Overlay calls with
Background = AddShadows(Background, Shadow, CenterX, CenterY, 0.4, 8)

MrC
25th September 2008, 10:43
All,

I would like to inform you that DropShadow function has been added to and it is used by AVStoDVD 2.1.1 Alpha (http://avstodvd.googlepages.com/home) to generate simple (and now more beautiful) DVD Menus.

Many, many :thanks:

Bye