almightyegg Posted March 30, 2008 Share Posted March 30, 2008 <? header("Content-type: image/png"); include "map1.php"; if($p1d2 == x){ $im = imagecreate(10, 10); imagefilledrectangle($im, 0, 0, 10, 10, imagecolorallocate($im, 0, 0, 0)); } if($p3d1 == x){ $im = imagecreate(10, 10); imagefilledrectangle($im, 10, 10, 20, 20, imagecolorallocate($im, 0, 0, 0)); } imagepng($im); imagedestroy($im); ?> To my knowledge this should make 2 black squares, 10x10 one starting at 0,0 and the other at 10,10. It is currently making 1 black square at 0,0....or maybe 2 on top of each other at 0,0 Why isn't it? It is running the IFs correctly Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/ Share on other sites More sharing options...
Barand Posted March 30, 2008 Share Posted March 30, 2008 is "x" a predefined constant? Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-504961 Share on other sites More sharing options...
almightyegg Posted March 30, 2008 Author Share Posted March 30, 2008 In map1.php (the file that is included) it says: $p1d3 = o; $p2d3 = o; $p3d3 = x; $p4d3 = x; $p5d3 = o; $p6d3 = x; $p7d3 = o; $p8d3 = x; $p9d3 = o; etc... That answer your question or not? Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-504975 Share on other sites More sharing options...
Barand Posted March 30, 2008 Share Posted March 30, 2008 Those should be 'o', 'x'. Your problem is you use imagecreate twice. You should create 1 image at start, draw squares, output the image Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-504995 Share on other sites More sharing options...
almightyegg Posted March 30, 2008 Author Share Posted March 30, 2008 Right.... So if I want 150 blacksquares to show, 15 per row, 10 rows, how do I do that? Because no matter what I try it shows one 10x10 square Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505009 Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 Your problem is you use imagecreate twice. You should create 1 image at start, draw squares, output the image Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505012 Share on other sites More sharing options...
almightyegg Posted March 30, 2008 Author Share Posted March 30, 2008 I'm done that. Though I'm not sure I have done it right/... $im = imagecreate(10, 10); if($p1d2 == x){ imagefilledrectangle($im, 0, 0, 10, 10, imagecolorallocate($im, 0, 0, 0)); }elseif($p == $p1d2){ imagefilledrectangle($im, 0, 0, 10, 10, imagecolorallocate($im, 255, 0, 0)); }elseif($p1d2 == v){ imagefilledrectangle($im, 0, 0, 10, 10, imagecolorallocate($im, 255, 0, 0)); }else{ imagefilledrectangle($im, 0, 0, 10, 10, imagecolorallocate($im, 255, 0, 0)); } if($p3d1 == x){ imagefilledrectangle($im, 10, 10, 20, 20, imagecolorallocate($im, 0, 0, 0)); }elseif($p == $p3d1){ imagefilledrectangle($im, 10, 10, 20, 20, imagecolorallocate($im, 255, 0, 0)); }elseif($p3d1 == v){ imagefilledrectangle($im, 10, 10, 20, 20, imagecolorallocate($im, 255, 0, 0)); }else{ imagefilledrectangle($im, 10, 10, 20, 20, imagecolorallocate($im, 255, 0, 0)); } Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505013 Share on other sites More sharing options...
Barand Posted March 30, 2008 Share Posted March 30, 2008 if image is 10 x 10 all other squares are outside the image <?php header("Content-type: image/png"); include "map1.php"; $im = imagecreate(150, 100); if($p1d2 == 'x'){ imagefilledrectangle($im, 0, 0, 10, 10, imagecolorallocate($im, 0, 0, 0)); } if($p3d1 == 'x'){ imagefilledrectangle($im, 10, 10, 20, 20, imagecolorallocate($im, 0, 0, 0)); } imagepng($im); imagedestroy($im); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505014 Share on other sites More sharing options...
Barand Posted March 30, 2008 Share Posted March 30, 2008 You shuld only allocate color once <?php header("Content-type: image/png"); include "map1.php"; $im = imagecreate(150, 100); $black = imagecolorallocate($im, 0, 0, 0); if($p1d2 == 'x'){ imagefilledrectangle($im, 0, 0, 10, 10, $black); } if($p3d1 == 'x'){ imagefilledrectangle($im, 10, 10, 20, 20, $black); } imagepng($im); imagedestroy($im); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505016 Share on other sites More sharing options...
almightyegg Posted March 30, 2008 Author Share Posted March 30, 2008 That just makes a solid black square 150x100 :-/ Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505017 Share on other sites More sharing options...
almightyegg Posted March 30, 2008 Author Share Posted March 30, 2008 The problem is sorted. Thanks. But I have another now Instead of typing 150 ifs out I thought I would try and be clever and use a while to do it... This is it: $i = 1; $h = 1; while($i <> 16 && $h <> 11){ $p = ${"p" . $i . "d" . 1}; $f = ($i-1)*10; $s = $i*10; $g = ($h-1)*10; $r = $h*10; $black = imagecolorallocate($im, 0, 0, 0); $red = imagecolorallocate($im, 255, 0, 0); $brown = imagecolorallocate($im, 255, 255, 255); $turq = imagecolorallocate($im, 153, 255, 255); if($p == x){ imagefilledrectangle($im, $f, $g, $s, $r, $black); }elseif($p == v){ imagefilledrectangle($im, $f, $g, $s, $r, $turq); }elseif($p == o){ imagefilledrectangle($im, $f, $g, $s, $r, $brown); } if($i == 15 && $h == 10){ $h = $h+1; $i = $i+1; }elseif($i == 15){ $i = 0; $h = $h+1; }else{ $i = $i+1; } } $i represents the 15 columns $h represents the 10 rows Instead of showing what it's meant to it shows: What is the problem?? Quote Link to comment https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505074 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.