473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

multiple polygons on one image

Is it possible to create more than one polygon (using the imagepolygon
function) and then paste them on to one image? i have no idea how to do
this. I did post this a few days ago but my computer seems to have lost the
reply,

thanks Dave
Jul 17 '05 #1
3 2168
David wrote:
Is it possible to create more than one polygon (using the imagepolygon
function) and then paste them on to one image? i have no idea how to do
this. I did post this a few days ago but my computer seems to have lost the
reply,

thanks Dave

The original response you got (from Pedro Graca) was:
What have you tried?
What happenned? What did you want to happen?


After taking a look at the sample code from PHP.net I can see how
somebody new-ish to PHP might be a bit confused. (An array is defined
within a function call, etc... not the world's clearest example, IMHO.)

Here's a hopefully clear(er) version. Also, note that I intentionally
chose long, descriptive variable names to hopefully help clarify what's
going on in the script. You probably won't want to use
reallySuperStinkingLongVariableNames in your scripts. ;)

- Dan
http://blog.dantripp.com/

================================================== =========
Modified version of the sample at:
http://www.php.net/manual/en/function.imagepolygon.php
================================================== =========

<?php

// create a blank image
$image = imagecreate(400, 300);

// fill the background color
$bg = imagecolorallocate($image, 0, 0, 0);

// choose a color for the polygon
$polygonOneColor = imagecolorallocate($image, 255, 255, 255);
$polygonTwoColor = imagecolorallocate($image, 160, 160, 160);

// Put the points for each polygon into an array, for the sake of
// showing simpler code than declaring an array within a
// function. (like the sample above)
// Also, I padded the values below with spaces, just to make these
// easier for human eyes to read. (aka - it's not necessary)
$polygonOnePoints = array( 0, 0, 200,200, 200,300);
$polygonTwoPoints = array(300,270, 250,225, 375,275);

// A smarter way to determine the number of points would be to count the
// # of items in the polygon's Points array and divide by 2 (left as an
// exercise for the reader).
$polygonOneNumberOfPoints = 3;
$polygonTwoNumberOfPoints = 3;

// draw the first polygon
imagepolygon($image,$polygonOnePoints,$polygonOneN umberOfPoints,$polygonOneColor);

// draw the second polygon
imagepolygon($image,$polygonTwoPoints,$polygonTwoN umberOfPoints,$polygonTwoColor);

// output the picture
header("Content-type: image/png");
imagepng($image);

?>
Jul 17 '05 #2
Thanks that really helped, is it that obvious im a newbie :) ?

Dave

ps Id managed to work this one out though! But thanks
// A smarter way to determine the number of points would be to count the
// # of items in the polygon's Points array and divide by 2 (left as an
// exercise for the reader).


"

Jul 17 '05 #3
David wrote:
Thanks that really helped, is it that obvious im a newbie :) ?

Dave

ps Id managed to work this one out though! But thanks
// A smarter way to determine the number of points would be to count the
// # of items in the polygon's Points array and divide by 2 (left as an
// exercise for the reader).


I think it's kinda dopey that the function asks for it (number of
points)... one would think that if it got three sets of x,y coords that
it'd know "I've got three points!" instead of one having to specify it.
There's some aspect of that implementation I just don't get. =)

Frankly, I thought the question was odd until I looked at the sample on
php.net. Then I thought "that's not such a good example" and did my
best to write a better one. Glad it helped.

I didn't mean "new-ish" in a derogatory manner. Everybody starts
somewhere. I learn something every day. =)

Regards,

- Dan
http://blog.dantripp.com/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David | last post by:
i am using the imagepolygon function to create a shape on an image i have, however i want to put more than just one polygon onto this image, i have no idea how to do this. Do i have to call the...
1
by: smjmitchell | last post by:
Hi All, I am developing a application in VB 6.0. I need to plot a 3D mesh of quadrilateral and triangular polygons. I have this working OK in wireframe. The question I have is what is the...
3
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
6
by: yk | last post by:
Hi, Is it a technique available in html/javascript in order to display same image many many times on a same page? Because of a large page loading I am looking for a way not to have same...
1
by: weberwhennner | last post by:
Hi All, Since two days Ive been trying to draw lines and polygons interactively (using mouse clicks), but all ive found is some libraries that draw shapes using predefined cooredinates. Ive...
19
by: traviscoop | last post by:
I have 3 images that I want to make look like a single image as a background to some text. I have looked at a lot of "rounding" techniques, basically this will look like a box with rounded corners,...
6
by: Number 11950 - GPEMC! Replace number with 11950 | last post by:
Are polygonal buttons or perhaps polygons with tooltips and and click events available in VS8 or is it too early yet? Thanks in advance... -- Timothy Casey GPEMC! >11950 is the...
1
by: nttamdn | last post by:
Anyone help me please. I want anytime mousemove to one polygon, it's opacity becomes 0.3, and mouseout polygon, i'ts opacity return to 0 again. I means mousemove to show the polygon and hiding it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.