Miscellaneous
  Home arrow Miscellaneous arrow Page 5 - Adding Drop Shadows with PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Adding Drop Shadows with PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2005-01-24

    Table of Contents:
  • Adding Drop Shadows with PHP
  • Setting the Shadow Options
  • Opening the Canvas
  • Allocating the Color Pallette
  • Drawing on the Canvas
  • Overlay the Original
  • Combined Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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
    ($image0,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 &ltcount($colors); $i++) {
      
    imagefilledrectangle($imageDS_OFFSETDS_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.

    More Miscellaneous Articles
    More By bluephoenix


       · Nice, this could come in handy.IS it easy to do this with Text?
       · Is it possible to make the dropshadow fade to a transparent value?Not that its a...
       · I am trying to learn PHP, and these tutorials have been a good place to practice. ...
       · The script can be called as with any other PHP script with a direct URI such as...
       · it works but is just solid and goes all around the right and bottom side
       · It could be a few things. When I was developing it, this happened to me a few times...
       · Timothy,This is some great code and a great idea. However, there are a few...
       · i used the code and works perfect for the jpeg images of my website...but i have a...
       · I get the following errorParse error: parse error, unexpected '=', expecting ')'...
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway