SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about GDlib, and "Stacking" images

    This is my first time using GDlib, so I do this an it works well right.
    I am doing two imagecopies() -- is that ok?

    I want to stack images in order to make a character creator, so Ill have like 5 body parts stacked on top of eachother to create an image. Im not worried about positioning right now.

    Is this the best way to go about it?
    Would I just repeat this 5 times to get 5 png's layered and then on one image?

    Thanks for time, If i fall asleep ill repsond once i wake up, been coding all night :P


    PHP Code:
    <?php


    $stamp 
    imagecreatefrompng('logo.png');
    $stamp2 imagecreatefrompng('pig.png');
    $im imagecreatefromjpeg('dog.jpeg');



    $sx imagesx($stamp); // Image Height
    $sy imagesy($stamp); // image Width

    $sx2 imagesx($stamp2); // Image Height
    $sy2 imagesy($stamp2); // image Width

    // Copy the stamp image onto our photo using the margin offsets and the photo 
    // width to calculate positioning of the stamp. 
    imagecopy(
        
    $im
        
    $stamp
            
    imagesx($im) - $sx 10
            
    imagesy($im) - $sy 10
            
    00
            
    imagesx($stamp), 
            
    imagesy($stamp)
            );
    imagecopy(
        
    $im
        
    $stamp2
            
    imagesx($im) - $sx2 24
            
    imagesy($im) - $sy2 22
            
    00
            
    imagesx($stamp2), 
            
    imagesy($stamp2)
    );
    // Output and free memory
    header('Content-type: image/png');
    imagepng($im);
    imagedestroy($im);
    ?>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've done very little work with gd, but assuming each layer has a transparent background, I think it should work. Although, you might need to tell gd to respect transparency.

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay sweet.

    I found a better way to do it from some guys example incase anyone wanted to know:

    PHP Code:
    <?php
    $layers 
    = array();
    $layers[] = imagecreatefromjpeg("maps/{$radar_id}_Topo_Short.jpg");
    $layers[] = imagecreatefromgif("maps/{$radar_id}_N0R_0.gif");
    $layers[] = imagecreatefromgif("maps/{$radar_id}_County_Short.gif");
    $layers[] = imagecreatefromgif("maps/{$radar_id}_Highway_Short.gif");
    $layers[] = imagecreatefromgif("maps/{$radar_id}_Rivers_Short.gif");
    $layers[] = imagecreatefromgif("maps/{$radar_id}_City_Short.gif");
    $layers[] = imagecreatefromgif("maps/{$radar_id}_N0R_Legend_0.gif");
    $layers[] = imagecreatefromgif("maps/{$radar_id}_Warnings_0.gif");

    $image imagecreatetruecolor(600550);



    for (
    $i 0$i count($layers); $i++)
    {
        
    imagecopy($image$layers[$i], 0000600550);
    }


    header('Content-type: image/jpeg');
    imagejpeg($image);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •