Trying to merge images

Discussion in 'PHP' started by egdcltd, Aug 12, 2009.

  1. #1
    Okay, I'm trying to create a final image by merging several (quantity will vary) images into one. This is the code I've got, but it's totally non-functional. I know I'm doing something wrong, but I don't know what.

    //Define base background image
    $base_background = imagecreatefromgif('adr/images/misc/landscape.gif');
    
    //Output background image
    $background_image = '';
    
    //Merge
    imagecopy($background_image,$base_background,0,0,0,0,1000,839);
    
    //Check if image active
    if($mw_image)
    {
    	$mw_image = imagecreatefromgif('adr/images/buildings/inner_wall_139.gif');
    	//Merge images
    	imagecopy($base_background,$mw_image,0,0,0,0,1000,839);
    
    }
    PHP:
     
    egdcltd, Aug 12, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your $background_image is blank, it needs to be an actual image resource, so instead of = '' needs to be something like this.

    
    $background_image = @imagecreatetruecolor(1000, 839) ;
    //sets background to black
    imagecolorallocate($background_image, 0, 0, 0);
    
    Code (markup):
    And you may want to use imagecopymerge and not imagecopy if you're trying to put the base background on top of the $background_image.
     
    kblessinggr, Aug 12, 2009 IP