[These pages contain ready ASP scripts. You can use them in your own applications]

VBS SCRIPT: Drop a shadow


Note: all scripts examples included in these Web pages are absolutely free. You can copy, use, and modify these scripts anyway you want. The scripts are published without warranty of any kind.

  View script result (shadow.jpg)

What is this

This scripts draws a box with text over existing image and makes it look 3D by giving it a drop shadow. There are two different ways in ShotGraph to get such effect. The simpliest way is to place black or gray rectangle over background image before drawing box. However, a bit more complicated, but giving more realistic result way is the making the shadow semi-transparent. This script applies semi-transparent shadow.
To make this script more simple, checkings if image has been loaded successfully were omitted.

The script performs the following steps to create the target image:

  1. gets dimensions of background image file
  2. creating primary imagespace of necessary size and read image there
  3. creating secondary imagespace and filling it with shadow color
  4. calling TransparentCopy method to create a semi-transparent copy of secondary imagespace in the promary imagespace
  5. drawing box with text over shadow with necessary offset
The most of important values (filename, shadow offset etc.) are described as variables in the beginning of the script: this let you easy modify the script for your needs.

File shadow.vbs
Set g = CreateObject("shotgraph.image")

' Dimensions of box
box_width = 320
box_height = 240
' Shadow offset
sh_offset = 15
' Shadow transparency (0-100)
sh_transparency = 25
' Path to source file
filename = "c:\winnt\web\wallpaper\paradise.jpg"

' Retrieving info about image size
g.GetFileDimensions filename,xsize,ysize

' Calculating the position of top left corner
' of the box on the bigger background image
boxx = (xsize-box_width)\2
boxy = (ysize-box_height)\2

' Creating primary imagespace and read image there
g.CreateImage xsize,ysize,16
g.ReadImage filename,pal,0,0

' Creating secondary imagespace...
g.InitClipboard box_width,box_height
' and making it active
g.SelectClipboard True
' Color #0 -- black color for shadow
g.SetColor 0,0,0,0
g.SetBgColor 0
' Filling secondary imagespace with color #0
g.FillRect 0,0,box_width,box_height
' Creating semi-transparent box
g.TransparentCopy boxx + sh_offset,boxy + sh_offset,box_width,box_height,0,0,0,sh_transparency
g.SelectClipboard False

' DRAWING BOX WITH TEXT
' Color #1 -- cyan color for box
g.SetColor 1,102,255,255
' Color #2 -- dark blue color for box border and text
g.SetColor 2,0,0,102
g.SetBgColor 1
g.SetDrawColor 2
g.Rectangle boxx,boxy,boxx+box_width-1,boxy+box_height-1

' Drawing text on text box
g.SetTextColor 2
g.SetBkMode "TRANSPARENT"
g.SetTextAlign "TA_CENTER","TA_BASELINE"
g.CreateFont "Verdana",0,45,200,True,False,False,False
g.TextOut xsize\2,ysize\2,"SHADOW"

g.JpegImage 95,0,"shadow.jpg"


Back to examples