KingOfHeart Posted November 6, 2009 Share Posted November 6, 2009 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. Quote Link to comment Share on other sites More sharing options...
Garethp Posted November 6, 2009 Share Posted November 6, 2009 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 Quote Link to comment Share on other sites More sharing options...
gizmola Posted November 6, 2009 Share Posted November 6, 2009 The alternative is a switch statement. If you set up some arrays, you could also potentially use either the letter itself as an index into the array, or the letter's ord() value. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.