Jump to content

php image and arrays


KingOfHeart

Recommended Posts

I'm wondering how can I copymerge a php image with an array instead of using if statements.

 

$string = "#BBBBBBBBBBBBBBBBBBBB|BBBBBBBBBBBBBBBBBBBB|BBBBBBBBBBBBBBBBBBBB|BBBAEEEEEBGDGGGGEBBB|BBBCEEGGGBGBBBBBEBBB|BBBFEEGGJBGGDGGDGBBB|BBBKGGGGGBGBBB0B0BBB|BBBBBBBBBBGBJB000BBB|BBBKCDEBEBGD0D000BBB|BBBCCCCBEBGBBB00BBBB|BBBCCC0BEBGBEB0BBBBB|BBBCD000GGGBEB0BBBBB|BBBBBB00BBGBEB0BBBBB|BBBBBBBFBIGGG00BBBBB|BBBBBBBBBBBBBBBBBBBB|*";


header("Content-type: image/png");
$im = imagecreate(320, 240);
$im2    = imagecreatefromPNG("../images/zeldaminer/zmingrid.PNG");
$obj1    = imagecreatefromPNG("../images/zeldaminer/zminbrick.PNG");
$bg    = imagecolorallocate($im, 255, 255, 255);
$tcolor    = imagecolorallocate($im, 0, 0, 0);
imagecopymerge($im, $im2, 0, 0, 0, 0, 320, 240,100);

 

I need each letter A - M to represent an image. Letter B is going to be $obj1, the rest will be created later. Right now I'm using this to handle it.

 

if($string[$n] == 'B')

{

imagecopymerge($im, $obj1, $ix, $iy, 0, 0, 16, 16,100);

}

 

I'd rather not use an if statement for each letter, so how to set it up so each letter will copymerge the image?

 

0s | and * won't use any image, so don't worry about this.

Link to comment
https://forums.phpfreaks.com/topic/180512-php-image-and-arrays/
Share on other sites


function Do($im, $obj1, $ix, $iy, $L)
{
switch ($L)
	{
	case "B":
		imagecopymerge($im, $obj1, $ix, $iy, 0, 0, 16, 16,100);
		break;
	}
return $im;
}

for($i=0; $i<strlen($string);$i++)
{
if($i == "#" || $i == "|")
	{
	continue;
	}

$im = Do($im, $obj1, $ix, $iy, $string[$i]);
}

 

Something like that

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/180512-php-image-and-arrays/#findComment-952317
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.