Miscellaneous

  Home arrow Miscellaneous arrow Page 5 - Adding Drop Shadows with PHP
MISCELLANEOUS

Adding Drop Shadows with PHP
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 12
    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

  •  
     

    SEARCH CODEWALKERS

    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

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Attention: Forum and Site Maintenance
    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength

    Developer Shed Affiliates

     



    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap