Jump to content

Recommended Posts

<?
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

Link to comment
https://forums.phpfreaks.com/topic/98665-gd-library/
Share on other sites

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));
}

Link to comment
https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505013
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505014
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505016
Share on other sites

The problem is sorted. Thanks. But I have another now :P 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:

map1err.JPG

 

What is the problem??

Link to comment
https://forums.phpfreaks.com/topic/98665-gd-library/#findComment-505074
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.