Adding Drop Shadows with PHP - Drawing on the Canvas
(Page 5 of 7 )
With the canvas ready and the necessary colors allocated, we can now draw the drop shadow. We'll begin by drawing a rectangle that covers the entire canvas to act as a flood fill of the background color.
<?php imagefilledrectangle($image, 0,0, $width, $height, $colors[0]); ?> |
The imagefilledrectangle function accepts the image on which to draw, the starting x and y coordinates for the upper left corner of the rectangle, the x and y coordinates for the rectangle's bottom corner and the color to use. The coordinates of the canvas start at 0,0 at its top left corner.
Each successive rectangle can be drawn using a for loop.
<?php for ($i = 0; $i < count($colors); $i++) { imagefilledrectangle($image, DS_OFFSET, DS_OFFSET, $width, $height, $colors[$i]); $width -= DS_SPREAD; $height -= DS_SPREAD; } ?> |
The drop shadow should be offset from the top left corner of the canvas the value of the DS_OFFSET constant defined earlier. The height and width of each successive rectangle is smaller than the pervious based on the DS_SPREAD constant.
It’s easy at this point to see how the options we initially set can influence the shadow's appearance. A larger DS_OFFSET would move the drop shadow further down and to the right. A small DS_STEP would create a less blended gradient. A larger DS_SPREAD would make each step wider and more discernable.

Remember, I've assigned the constants initial values that I find reasonable and work well for my implementation. Your needs and preferences may vary.
Next: Overlay the Original >>
More Miscellaneous Articles
More By bluephoenix