So say you have 6 images, 40 x 40, that you want to make a 3x2 rectangle following typical left-to-right reading rules so that the images are tiled horizontally and wrapped to the next line. Now, we know that you'll have one image at 0,0 and another at 40,0; now you're on to the next row, so you'll position it at 0,40 and the next image is at 40,40; now you're on the last row, so you'll position it at 0,80 and the last at 40,80.
The only thing that's left is to use [man]imagecopymerge[/man] to take the source images and place them into the main canvas at specific points. For example, to make our collage statically (meaning we won't be looping anything) your image would look like:
$new = imagecreatetruecolor(80,120); // Create our canvas
// Our static positions...
$pos = array(array(0,0), array(40,0), array(0,40), array(40,40), array(0,80), array(40,80));
$height=40;
$width=40;
$white = imagecolorallocate($new, 255,255,255); // Gives us a white background
// Now, define the source images
$src = array('images/image1.gif', 'images/image2.gif', 'images/image3.gif', 'images/image4.gif', 'images/image5.gif', 'images/image6.gif');
foreach($src as $key=>$image)
{
$old = imagecreatefromgif($image);
imagecopymerge($new, $old, $pos[$key][0], $pos[$key][1], 0, 0, $width, $height, 100);
}
header('Content-Type: image/gif');
ImageGIF($new);
It has one small loop, but it's easy to figure out what it's doing. Now, you can adapt this to read the height and width of different images and also dynamically generate where the images should be located. But keeping images the same size(s) really simplifies things.
** Note: I have not tried that code. It may or may not work. I can only attest to it being a framework for an idea, not necessarily working code.