Page 1 of 1

while loop?

Posted: Sat May 27, 2006 9:06 pm
by elecktricity
I have a 300x300 image, and have an image which is 30x30, I want it to be overlayed all over the background image, thats 10 by 10 images which would take 100 imagecopymerge things so I decided a while loop would be best and I dont know why this isnt working... this just displays a 30x30 brown square.

Code: Select all

<?PHP
$bg = imagecreatefromgif("background.gif");
$h1 = 0;
$h2 = 0;
while ($h1 <= 270) {
	$i = imagecreatefromgif("rock.gif");
	imagecopymerge($bg, $i, 0, 0, $h1, $h2, 30, 30, 100);
	$h2 += 30;
	if($h2==300) {
		$h2 = 0;
		$h1 += 30;
	}
}
header("Content-type: image/gif");
imagegif($bg);
imagedestroy($bg);
?>

Posted: Sat May 27, 2006 10:16 pm
by Flamie

Code: Select all

<?
$bg = imagecreatefromgif("background.gif"); 
$im = imagecreatefromgif("rock.gif");
$wim = imagesx($im);
$him = imagesy($im);
for($i=0;$i<10;$i++)
{
	for($j=0;$j<10;$j++)
	{
		$x = $i * 30;
		$y = $j *30;
		imagecopymerge($bg, $im, $x, $y, 0, 0, $wim, $him, 100);
	}

}
imagedestroy($im);
header("Content-type: image/gif");
imagegif($bg);
imagedestroy($bg);
?>