GetDotted Domains

Viewing Thread:
"Creating filled polygons with PHP"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Fri 12/09/03 at 13:30
Regular
"Pouch Ape"
Posts: 14,499
Hi. I ripped and edited this code from the PHP.net site to make a filled polygon from a set of variables posted through a form:

$values = array(
0 => $a_x, // x1
1 => $a_y, // y1
2 => $b_x, // x2
3 => $b_y, // y2
4 => $c_x, // x3
5 => $c_y, // y3
6 => $d_x, // x4
7 => $d_y, // y4
);
$im = imagecreate(500, 500);
$bg = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 0, 0, 255);
imagefilledpolygon($im, $values, 4, $blue );
?>

But surprise, surprise, it doesn't work for me. I don't get any error messages though. Any ideas?
Sun 14/09/03 at 11:07
Regular
"Pouch Ape"
Posts: 14,499
Yeah, that makes sense! I'm such a duuuur brain.
Sat 13/09/03 at 15:30
Regular
"Devil in disguise"
Posts: 3,151
monkey_man wrote:
> Yeah, I changed the colours around on purpose just to make sure that
> the imagecreate was working. It doesn't matter about that for now.
> When assigning the variables, can it be done straight from the posted
> form, or do I need to post to another variable and then use that
> within the array?

Well, you need to post the variables to image.php, something like


(of course with all your vars)
Sat 13/09/03 at 12:37
Regular
"Pouch Ape"
Posts: 14,499
just checking and the array does work with my own numbers, just not the posted variables...

I don't need to "print" the variables, do I?
Sat 13/09/03 at 12:27
Regular
"Pouch Ape"
Posts: 14,499
Yeah, I changed the colours around on purpose just to make sure that the imagecreate was working. It doesn't matter about that for now. When assigning the variables, can it be done straight from the posted form, or do I need to post to another variable and then use that within the array?
Sat 13/09/03 at 11:57
Regular
"Devil in disguise"
Posts: 3,151
Well, first thing, I notice you've inverted your colours, ie blue background and filling the polygon with white, which is why you have a blue box and nothing in it. But besides the point at present.

In your image.php file how are the values in the array being assigned? At the moment, they map to variables, $a_x, $a_y etc. but you're not showing any assignment of them. The array itself is fine, and you are using it in the right manner with ImageFilledPolygon. If you replace $a_x etc. with your own numbers, it does work so presumably your variables aren't being assigned.
Sat 13/09/03 at 10:57
Regular
"Pouch Ape"
Posts: 14,499
Hmmm. Now I have this for image.php:

Header ("Content-type: image/png");
$values = array(
0 => $a_x,
1 => $a_y,
2 => $b_x,
3 => $b_y,
4 => $c_x,
5 => $c_y,
6 => $d_x,
7 => $d_y, );
$im = Imagecreate(500, 500);
$bg = ImageColorAllocate($im, 0, 0, 255);
$blue = ImageColorAllocate($im, 255, 255, 255);
ImageFilledPolygon($im, $values, 4, $blue );
ImagePng ($im);
ImageDestroy ($im); ?>

Then a php file that has the content "".

But I still get just a blue box, which leads me to deduce, with my Columbo-esque superpowers that it's something to do with how the variables are being fed through. Can anyone see a problem with what I'm doing for the array?
Sat 13/09/03 at 10:41
Regular
"Pouch Ape"
Posts: 14,499
OK, I've done as you've suggested and it actually creates an image! But the polygon doesn't appear at all. It's just a blank white image.
Sat 13/09/03 at 00:12
Regular
"bing bang bong"
Posts: 3,040
Make sure there are no spaces at the top or bottom of your source, outside of the php tags.
Fri 12/09/03 at 17:45
Regular
"Devil in disguise"
Posts: 3,151
Hm, ok..

The code to create the image should be in a separate file called image.php or whatever, which should then be called via an image link in the page you want it displayed on e.g.

Fri 12/09/03 at 17:22
Regular
"Pouch Ape"
Posts: 14,499
OK, now I have this:

$values = array(
0 => $a_x,
1 => $a_y,
2 => $b_x,
3 => $b_y,
4 => $c_x,
5 => $c_y,
6 => $d_x,
7 => $d_y, );
$im = Imagecreate(500, 500);
$bg = ImageColorAllocate($im, 255, 255, 255);
$blue = ImageColorAllocate($im, 0, 0, 255);
ImageFilledPolygon($im, $values, 4, $blue );
ImagePng ($im);
ImageDestroy ($im);
?>
">

All the breaks are taken out in the uploaded code, so it's one big line of text. I get a broken image and still gibberish underneath. Is there anything wrong with the fundamentals of this, or is it something secret that only FREEOLA would know?

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

First Class!
I feel that your service on this occasion was absolutely first class - a model of excellence. After this, I hope to stay with Freeola for a long time!
LOVE it....
You have made it so easy to build & host a website!!!
Gemma

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.