Create polygon and loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

Create polygon and loop

Post by kumarrana »

I am drawing polygon using following functions. Code works just fine but I would like to create multiple of them in one HTML page. I have tried looping and changing the $pageHeight every-time it loops. It did not work. Anyone have any idea how I can create multiple of similar polygon using sample script below? I am attaching sample source code and the result. Thank you for help in advance. (Note:this is sample only and would not work if you copy and paste)

Code: Select all

$image = imagecreatetruecolor($paneWidth, $pageHeight);
$background = imagecolorallocate($image, 255, 255, 255);        
imagefill($image, 0, 0, $background);
$textColor = imagecolorallocate($image, 0, 0, 0);    
drawVector($x_1, $y_1, $x_2, $y_2, $x_3, $y_3, $x_4, $y_4);  
imagefilledpolygon($image,$createVector, 4, $polygonFill); 
imagestringup($image, 3,($x_1 + $x_2)/2, $y_1-5,$CarrierLabel,$textColor); 
header('Content-type: image/png');
imagepng($image);  
imagedestroy($image);    
Attachments
This is the intended result.
This is the intended result.
I can get this created without problem though
I can get this created without problem though
Last edited by kumarrana on Tue Dec 02, 2014 3:13 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Create polygon and loop

Post by requinix »

Copy the code that draws the polygon.

Code: Select all

drawVector($x_1, $y_1, $x_2, $y_2, $x_3, $y_3, $x_4, $y_4);
imagefilledpolygon($image,$createVector, 4, $polygonFill);
Probably the part that writes the string too.

Code: Select all

imagestringup($image, 3,($x_1 + $x_2)/2, $y_1-5,$CarrierLabel,$textColor);
You'll have to adjust the numbers/variables as needed to put them where you want in the image, and of course you'll have to change the size of the image to fit however many more polygons you want to add to it.
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

Re: Create polygon and loop

Post by kumarrana »

I am not sure I understood what you suggesting. Can you explain little more. I am not expert on PHP. I was hoping something keep imagecreatetruecolor inside the loop. I am attaching my intended result.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Create polygon and loop

Post by requinix »

If you want three separate images then you can't do this with just the one PHP script. You'll need an HTML page (or whatever you already have) to reference the three individually, then you can set up one script (or three) for the images.

But if you want one image with three shapes in it then it's like I said.
kumarrana wrote:I was hoping something keep imagecreatetruecolor inside the loop.
Assuming it's the "one image" choice, doing that doesn't make sense. imagecreatetruecolor() creates an image of whatever dimensions. You only do that once. What you repeat is the part that draws the polygon and writes the text.
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

Re: Create polygon and loop

Post by kumarrana »

Thanks! It makes sense
Post Reply