Miscellaneous

  Home arrow Miscellaneous arrow Page 6 - 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 - Overlay the Original


    (Page 6 of 7 )

    The final step is to overlay the original image and send the results back to the requesting browser.

    The imagecopymerge function can be used to copy a section of one image onto another.

    <?php
    $original_image 
    imagecreatefromjpeg($src);
    imagecopymerge($image$original_image0,00,0$o_width$o_height100);
    ?>

    The imagecopymerge function accepts the base image, the overlay image, coordinates where to place the overlay on the base image, cropping coordinates for the overlaid section and an alpha transparency.

    The overlaid image should be positioned at the top left of the base image. Since the entire original image will be superimposed, it's cropped coordinates should be 0,0 to its width and height. The image should be fully opaque so a value of 100 should be passed for the alpha.

    The final results can then be sent to the browser using imagejpeg.

    <?php
    header
    ("Content-type: image/jpeg");
    imagejpeg($image""100);
    ?>

    By sending a Content-Type header, we are creating a PHP script that outputs the jpeg file directly to the browser.

    The imagejpeg function can either save the image to a file or send the image directly to the request. By specifying an empty string for the file name it knows we wish to output the image directly to the browser. You can also set the compression quality of the image, which I have set at 100.

    Once the image has been sent it's good practice to free up the resources we've consumed to generate it.

    <?php
    imagedestroy
    ($image);
    imagedestroy($original_image);
    ?>

    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