I am trying to write some code that will take 3 random images and combine them into 1 jpeg with all images side by side.
The code I have so far successfully chooses the 3 images, then imports them as image resources. However, I'm stuck at this point on where to continue. I've tried using imagecopymerge() but without success.
Here's my current code. Please give me some tips.
<?
header ("Content-type: image/jpeg");
//number of images in library, 1 to X
$numbers = range(1, 3);
//shuffle the array
shuffle($numbers);
//get 3 images using previous array as random order source
for($i=0;$i<count($numbers);$i++){
$imgsrc[$i] = 'images2/' . $numbers[$i] . '.jpg';
}
for($i=0;$i<count($imgsrc);$i++){
//input each 3 images
$img[$i] = imagecreatefromjpeg($imgsrc[$i]);
}
$size = getimagesize("$img[1]");
$src_height = $size[1];
$src_width = $size[0];
//imagecopymerge(dest , src , dest_x , dest_y , src_x , src_y , src_width, src_height, quality)
imagecopymerge($img[0], $img[1], imagesx($img[0]), imagesy($img[0]), imagesx($img[1]), imagesy($img[1]), $src_width, $src_height, 100);
//imagejpeg($img[0],'', '100');
imagedestroy($img[0]);
?>