Results 1 to 6 of 6

Thread: Several Images in One [Resolved]

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Several Images in One [Resolved]

    I'm new to playing round with images in PHP so I was wondering if anyone could show me how I would have serveral images in the one generated image:
    Attached Images Attached Images  
    Last edited by Electroman; Feb 28th, 2004 at 08:29 AM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    do you want to open images and then send them out to a browser in one file? you can do that..

    do you want to create the images in PHP and then return them in one file? you can do that too..
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Originally posted by kows
    do you want to open images and then send them out to a browser in one file? you can do that..

    do you want to create the images in PHP and then return them in one file? you can do that too..
    First one....

    Say I have 7 image files named: Pic1.png, Pic2.png, Pic3.png, .....
    Then I want to create a image to be returned to the browser which contains the 7 images as shown in the attachment. The script will be actually be deciding which images go where but I don't need to worrie about that at the moment as I think I have that covered.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    I'll try to make something for you then.. I'll just make an example of 3 images, just so you'll get the general idea.. it might take me a while because my internet is pretty slow right now.
    Like Archer? Check out some Sterling Archer quotes.

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    ok, finished. I actually got it working on my first try, with minor bugs to fix, but it works perfectly now.. thought this would be a huge challenge, though.

    This is just for 3 images, so you get the general idea, and I'm not doing all of your work.

    PHP Code:
    <?
      //image merge script
      //     author: David Miles
      //     contact: [email][email protected][/email]

      //create an empty image to dump the images into
      $base = imageCreate(300, 40);
      //make a few temporary colors for debugging
      $black = imageColorAllocate($base, 0, 0, 0); //black
      $white = imageColorAllocate($base, 255, 255, 255); //white 
      //fill the image with black for easy debug in early stages
      imageRectangle($base, 0, 0, 300, 40, $black);

      //open the dump images
      $img1 = imageCreateFromPNG("img1.png");
      $img2 = imageCreateFromPNG("img2.png");
      $img3 = imageCreateFromPNG("img3.png");
      
      //copy the first image and place it in the 0,0 position
      imageCopy($base, $img1, 0, 0, 0, 0, imagesX($img1), imagesY($img1));
      //copy the second image and get the x coordinate by calculating first images width
      imageCopy($base, $img2, imagesX($img1), 0, 0, 0, imagesX($img2), imagesY($img2));
      //copy the third image and get the x coordinate by adding the first and second images' width
      imageCopy($base, $img3, imagesX($img1) + imagesX($img2), 0, 0, 0, imagesX($img3), imagesY($img3));
      
      //imagecopy(dst_im, src_im, dst_x, dst_y, src_x, src_y, src_w, src_h);
      
      //display the image
      imagePNG($base);
      imageDestroy($base);
    ?>
    I left in all of my debugging stuff I made to make sure I had it all working before I actually started adding images.. and anything else I added in to do things. I removed some irrelevant stuff that I was using to make sure I was actually making an image and it was showing up correctly.

    Here's a working example of the script:
    http://david.gamersepitome.net/files...y/img_copy.php

    And the original images that I made for this:


    Anyway.. Hope that helps you, and if you have any questions about my code, feel free to ask.
    Last edited by kows; Feb 28th, 2004 at 12:21 AM.
    Like Archer? Check out some Sterling Archer quotes.

  6. #6

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Thanx mate, just what I was after .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions

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



Click Here to Expand Forum to Full Width