Merge more than 5 images with php

Discussion in 'PHP' started by xDragonZ, May 7, 2011.

  1. #1
    Each letter is a different picture, How would i join all these pictures into one image with a php script?

    This what i've tried so far but the images appear on top of each other. and i dont want to php resize my image into smaller size..

    p/s : the images is in PNG.. with transparency ..

    <?php
    Header ("Content-type: image/gif"); 
    
    //Your first line of code must designate that it is, in fact, an image. Your image can be a ".php" file even if the content is of type gif, so don't worry about naming the image extension as a gif, as it is not necessary.
    $image1Url = '1.png';
    $image2Url = '2.png';
    $image3Url = '3.png';
    $image1 = imageCreateFromPNG($image1Url);
    $image2 = imageCreateFromPNG($image2Url);
    $image3 = imageCreateFromPNG($image3Url);
    
    //This will load the images passed in to the functions.
    
    $colorTransparent = imagecolorat($image1, 0, 0);
    imageColorTransparent ($image1, $colorTransparent);
    
    $colorTransparent = imagecolorat($image2, 0, 0);
    imageColorTransparent ($image2, $colorTransparent);
    
    $colorTransparent = imagecolorat($image3, 0, 0);
    imageColorTransparent ($image3, $colorTransparent);
    //The above is optional, but it will take the color in the (0,0) pixel of the image and make all of that color transparent for that image. You could also use the color allocate function and pass in the arguments (red,green,blue) for the color of your choice to make transparent. Doing it this way, you will have to convert from hex to base ten. So if your color is FFFF00, r=255, b=255, g=0.
    
      $offset2x = imagesx($image1);
        imageCopyMerge($image1, $image2, $offset2x, 0, 0, 0, 96, 96, 100);
    
        $offset3x = $offset2x + imagesx($image2);
        imageCopyMerge($image1, $image3, $offset3x, 0, 0, 0, 96, 96, 80);
    
    
    //This will copy image2 on top of image1. Check the arguments at the site I listed at the top, as this is just a messy function with a lot of stuff to pass in. I know the 96's are for the dimensions and I think the 100 is the opacity of the image on top.
    
    
    ImagePng ($image1);
    
    //This will create your image!
    
    ImageDestroy ($image1);
    ImageDestroy ($image2);
    ImageDestroy ($image3);
    ?>
    PHP:
     
    xDragonZ, May 7, 2011 IP
  2. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #2
    may be you should create a new background image and within that you should copy all the files and flatten to a single image.
     
    olddocks, May 7, 2011 IP