Miscellaneous
  Home arrow Miscellaneous arrow Page 2 - Overlapping Images with GD
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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

Overlapping Images with GD
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2004-09-18

    Table of Contents:
  • Overlapping Images with GD
  • Combining Images with GD
  • Imagecopymerge explained

  • 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


    Overlapping Images with GD - Combining Images with GD


    (Page 2 of 3 )

    In this tutorial, we'll cover the basics of placing a foreground image onto a background image.

    Here are some sample images.

    background image (backgroundimage.png):

    overlay image (overlayimage.png):

    Combined, they will look like this:

    The following code is used to achieve the overlay. Read through it; it's well commented.

      // The header line informs the server of what to send the output
      // as. In this case, the server will see the output as a .png
      // image and send it as such

      header ("Content-type: image/png"); 


      // Defining the background image. Optionally, a .jpg image could 
      // could be used using imagecreatefromjpeg, but I personally 
      // prefer working with png

      $background = imagecreatefrompng("backgroundimage.png"); 


      // Defining the overlay image to be added or combined.

      $insert = imagecreatefrompng("overlay.png"); 


      // Select the first pixel of the overlay image (at 0,0) and use
      // it's color to define the transparent color

      imagecolortransparent($insert,imagecolorat($insert,0,0));


      // Get overlay image width and hight for later use

      $insert_x = imagesx($insert); 
      $insert_y = imagesy($insert); 


      // Combine the images into a single output image. Some people
      // prefer to use the imagecopy() function, but more often than 
      // not, it sometimes does not work. (could be a bug)

      imagecopymerge($background,$insert,0,0,0,0,$insert_x,$insert_y,100); 


      // Output the results as a png image, to be sent to viewer's
      // browser. The results can be displayed within an HTML document
      // as an image tag or background image for the document, tables,
      // or anywhere an image URL may be acceptable.
     
      imagepng($background,"",100); 

    More Miscellaneous Articles
    More By Codewalkers


       · thanks a bunch for the tutorialit really helps me!
       · Hey,I have a problem, I am using a form to submit the two images in which the...
       · Thanx Chaos Zen,This was nearly exactly what I was looking for for a...
       · could this be used with a variable overlay eg $variable?
     

    MISCELLANEOUS ARTICLES

    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX
    - Fedora 10 Released
    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT