What you will need
- Photoshop (or some kind of image editing software)
- A server with PHP and GD Library Installed.
- An Image where the drop shadow will go
- A will to learn
The Process
- Create the drop shadow images in Photoshop
- Slice up the drop shadow graphic.
- Use GD Library to place the drop shadow beneath an Image of your choosing.
Source
Download the source and photoshop files.
Part One: Creating the Drop Shadow Images
Open up Photoshop then go to File > New and set the following settings.

Photoshop settings

Create a new layer named "base"
In the layers palette, click Create a new layer to create a new layer above “Background” name this new layer “base”.
Make sure that “base” is selected and then type Ctrl + A (Cmd + A for Mac). This will select everything; notice the dashed line moving around the document.
Now go to Select > Modify > Contract, give it a value of 15 pixels and hit “ok.” This will contract your selection by 15 pixels on all sides.

Shift + F5 to open up the fill dialog box. Select white from the dropdown list and hit OK.
Double Click the layer named “base” to open up the layer style window.
Set these settings below.

Add a dropshadow and apply these settings.
Tadaaa! A drop shadow!

Part Three: Slicing up the Drop Shadow Graphic
The next step is to cut that image up so that we can use it in GD library.
Go to window > Info (or hit F8) on your keyboard.
Make sure that the Slice Tool is selected by pressing K on your keyboard.
Hold down Shift and in your image, draw a square going from the top left-hand corner of the canvas, keep drawing until the width and height in the info palette reads .88 inches.
Right click this slice and click Edit Slice Options, name it shadow_TL.

Insert a corner slice
Do this for the remaining three corners and give them appropriate names. Such as shadow_BR and shadow_BL.
Once you’re done it should look something like this.

Near the center on the left hand side of the canvas draw a slice from the left side of the canvas going to the left side of the square.
Make sure that that slice is 1 pixel in height.
Right click > Edit Slice Options, name it shadow_L.

Do this for the remaining 3 sides. Again name them something like shadow_R, shadow_T, shadow_B.
You should have something like this.

Go to File > Save for Web and Devices
From this window hit K to select the Slice Select Tool and then select all 8 slices that you have created. You may need to zoom in, in order to select the correct slice.
Click Save in the top right hand corner.
Adjust the properties as shown below.

From the Settings dropdown list, choose Other.
Under the Saving Files section, make sure that Put Images in Folder is unchecked.

Press OK
Select the shadow folder and press Save.
It now just saved a copy of all your slices into the folder. 8 Images at once! Pretty cool huh?!
Part 3: Integrating the Graphic with GD Library
The Concept:
We’re going to leave Photoshop now and journey on over to our friendly neighborhood script editor. I prefer NotePad++ but any pure text editor will suffice.
- The graphic that you want to have the shadows go under.
- The shadow images that you just created.
- And a canvas to put the two together.
The canvas is the base for everything, the shadow graphics go on top of the canvas creating a kind of picture frame.
Then your image goes inside the shadow picture frame.

Ok, the idea seems simple enough. Time to get started.
The Code:
Open up your text editor and make a new file. Save it to the folder we called dropshadow and name it img.php.
Copy the following code into your file. For an explanation, please read the comments included.
// ----------------------------------------
// Image Storage
// ----------------------------------------
//STORING YOUR IMAGE
$graphic = "image.gif"; //the path to your image
list($width, $height) = getImageSize($graphic); //the width and height of your image
//storing the image into memory so that we can use it with GD Library
$image = imagecreatefromgif($graphic);
/*
Definition: imagecreatefromgif("folder/image.jpg");
This function creates a copy of an image and stores the image in a variable in php.
*/
//STORING THE DROP SHADOW IMAGES
//Below I'm storing all 8 shadow images into memory.
$tl = imagecreatefromgif("images/shadow_TL.gif");
$t = imagecreatefromgif("images/shadow_T.gif");
$tr = imagecreatefromgif("images/shadow_TR.gif");
$r = imagecreatefromgif("images/shadow_R.gif");
$br = imagecreatefromgif("images/shadow_BR.gif");
$b = imagecreatefromgif("images/shadow_B.gif");
$bl = imagecreatefromgif("images/shadow_BL.gif");
$l = imagecreatefromgif("images/shadow_L.gif");
//We now have stored all images that we are going to use.
//Next we have to create one more (the canvas) to put them together.
//CREATING THE CANVAS
/*
Remember, that the canvas has to be larger than the image, otherwise the image will hide the shadow images.
In this case the width of the canvas should be the width of the image plus twice the width of one of the side shadow image.
In other words: Width of Canvas = Width of Image + 2(Width of Side Image)
Read that again, it's easier than it sounds.
*/
//First we find the dimensions of the side images
$w = imagesx($l); //Width of the left shadow image
$h = imagesy($l); //Height of the left shadow image
/*
Next we get our new heights and widths for the canvas. This creates an image that is slightly larger than
your image.
*/
$canvasHeight = $height + (2*$w);
$canvasWidth = $width + (2*$w);
//Third we create a blank canvas with these new dimensions
$canvas = imagecreatetruecolor($canvasWidth, $canvasHeight);
// ----------------------------------------
// Putting your images together
// ----------------------------------------
/*
We have our graphic image, shadow images and canvas ready. Now it's time to paint!
In the first section we're adding the top, left, bottom and then right sections.
*/
imagecopyresized($canvas, $t,0,0,0,0,$canvasWidth,$w,$h,$w);
imagecopyresized($canvas, $l,0,0,0,0,$w,$canvasHeight,$w,$h);
imagecopyresized($canvas, $b,0,$canvasHeight-$w,0,0,$canvasWidth,$w,$h, $w);
imagecopyresized($canvas, $r,$canvasWidth-$w,0,0,0,$w,$canvasHeight,$w,$h);
//here I'm doing the same thing again, only this time I'm setting $w and $h to be the width and heights of the corners.
$w = imagesx($tl);
$h = imagesy($tl);
imagecopyresized($canvas, $tl,0,0,0,0,$w,$h,$w,$h);
imagecopyresized($canvas, $bl,0,$canvasHeight-$h,0,0,$w,$h,$w,$h);
imagecopyresized($canvas, $br,$canvasWidth-$w,$canvasHeight-$h,0,0,$w,$h,$w,$h);
imagecopyresized($canvas, $tr,$canvasWidth-$w,0,0,0,$w,$h,$w, $h);
/*
At this point the canvas has all the drop shadow images attached, all we need to do now is attach the image and we're done!
I changed $w back to the size of the perimeter in order to properly place the image.
*/
$w = imagesx($l);
imagecopyresampled($canvas, $image, $w,$w,0,0, imagesx($image), imagesy($image), imagesx($image),imagesy($image));
//Notice that I used imagecopyresampled, the reason for this is I get a much higher quality image than with imagecopy
//resized. However, I sacrifice speed for this quality.
// ----------------------------------------
// OUTPUTTING THE IMAGE
// ----------------------------------------
header("content-type: image/gif"); //This sets the header type (what kind of file is this?) quite literally this php file turns into a gif.
ImageGif($canvas);
ImageDestroy($canvas);
A lot of the functionality of the code is explained in the comments but I’ll spare a few minutes and summarize what it does.
There are three parts to this code.
- Image Storage and preparation
- Image manipulation
- Image Output (the easiest part)
- Image Storage
- We store the images so that we have access to them in the GD Library. What it is actually doing is creating a copy of the image and
storing them into memory.In this instance we also create a blank canvas by using the function createimagetruecolor. It is like making a new canvas in photoshop. From here
the possibilities are almost limitless. - Image manipulation
- Like photoshop, the power of manipulation is where the real strength lies. In this instance we are using the imagecopyresized function
to place the pictures onto each other (as illustrated in the picture above). The behavior is very similar to that of Photoshop. Click here for
more information about this powerful function. - Image Output
- This is the most straightforward part of the script. We simply set what kind of file this, ouput the file and then destroy the file and free up resources.
Result:
And here is the final result of all our hard work!

Conclusion
I hope you found this tutorial useful. If you have any questions or suggestions please feel free to post in my comments.
Comments
Post by AGMJ on June 21, 2007
ohh! man ur just great!!so that was how it was done?cool thxwhat about a tute on how to make that "desintegrate" effect on ur logo?
Post by Brandnew on June 30, 2007
Thank you so much for the script ! That's a great way to do it ! I guess there's not a way to use only PHP to create, with a function or something, the shadow ? Anyway, thank you !
Post by NetJunky on January 10, 2008
Hello! Im sorry but i am not so good with PHP. If you can, help please.
Post by Grzesiek on July 6, 2008
of course there's a way to create script which will return SIMILAR effect using ONLY php; however, my only idea to do it so is to connect some pictures using tables/divs combination with their backgrounds set to shadow.
Post by Laurens on November 5, 2008
i finally know how to use slices in PS now ^_^ To use gd for generating the entire image (including the graphics) creates an enormous server load and the quality of the output image seems to be less then the original. I would advise to generate the shadow seperate from the image and place it as a background behind the image in the web page. This way the file size is a lot smaller, png can be used for alpha transparency and it wil break down nicer when the server doesn't support GD (e.g. no shadow, instead of no image at all)
Post by Saeed on December 3, 2008
Nice tutorial! thanks alot. :)
Post by Joern on February 12, 2009
absolutely fabulous, thanks again for this great tutorial. Especially providing everything from image files and "3d" graphics for understanding!
Post by Dennis on June 27, 2009
I found it easier to save the whole Photoshop-generated dropshadow image as a single png template instead of separate slices. In my PHP script I then used GD's imagecopy() function to copy the corners of the template onto a re-sized canvas, and filled-in along the sides with an appropriate slice of shadow. The source image was then overlaid to complete the job.
Post by Crissaegrim on September 25, 2010
Thanks a lot for this approach! However adding twice shadow width to canvas width wasn't necessary for me.
Post by Simon on April 13, 2011
Here I did a function that applies an innershadow without the need of photoshop. It could be modified slightly for a dropshadow: function applyInnerShadow($im){ $sh_size = 15;#the size of the shadow $sh_alpha = 60;#opacity from 1 to 127 $imgw = imagesx($im); $imgh = imagesy($im); for($i=0; $i<$sh_size; $i++){ $shade_alpha = 127-round($sh_alpha*($sh_size-$i)/$sh_size); $shade = imagecolorallocatealpha($im, 0, 0, 0, $shade_alpha); imagefilledrectangle($im, 1+$i, 0+$i, $imgw-1-$i, 0+$i, $shade);#top imagefilledrectangle($im, 1+$i, $imgh-$i, $imgw-1-$i, $imgh-$i, $shade);#bottom imagefilledrectangle($im, 0+$i, 0+$i, 0+$i, $imgh-$i, $shade);#left imagefilledrectangle($im, $imgw-$i, 0+$i, $imgw-$i, $imgh-$i, $shade);#right } return $im; }