while loop?

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

while loop?

Post 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);
?>
Flamie
Forum Contributor
Posts: 166
Joined: Mon Mar 01, 2004 3:19 pm

Post 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);
?>
Post Reply