php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44491 filled Polygon is not visible after creating it 129th time in same image
Submitted: 2008-03-20 18:38 UTC Modified: 2008-03-21 05:37 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: swanand dot raikar at gmail dot com Assigned:
Status: Not a bug Package: GD related
PHP Version: 5.1.4 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: swanand dot raikar at gmail dot com
New email:
PHP Version: OS:

 

 [2008-03-20 18:38 UTC] swanand dot raikar at gmail dot com
Description:
------------
I have a function which creates a polygon of blue color. I call this function inside a loop of 128 iterations. For every iteration, i change the value of x and y so that my polygon is rendered on new location. This goes fine and i get 128 new polygons on my image after running the script. But if change the number to 129, the 129th polygon is transparent or what i cannot guess.It  just does not display or render at all. Is this a bug or some mistake with my code?

I am using php version 5.1.4 that came with WAMP5 Version 1.6.3





Reproduce code:
---------------
$im = imagecreate(600, 400);
$x = 20;
$y = 350;
for($i=1;$i<=128;$i++) //create a polygon 128 times
	{
		drawPoly($x,$y,$im);
		$x = $x+2;
		$y = $y-2;
	}
	header('Content-type: image/png');
	imagepng($im);
	imagedestroy($im);	
	function drawPoly($xCoord,$yCoord,$im)
	{
		$x1 = $x2 = $xCoord;
		$x3 = $x4 = $xCoord + 70;
		$y1 = $y4 = $yCoord;
		$y2 = $y3 = $yCoord + 30;
		$Poly = array(0  => $x1,1  => $y1,2  => $x2,3  => $y2,4  => $x3,5  => $y3,6  => $x4,7  => $y4);
		$bg   = imagecolorallocate($im, 150, 150, 150);
		$blue = imagecolorallocate($im, 0, 0, 255);
		imagefilledpolygon($im, $Poly, 4, $blue);
	}

Expected result:
----------------
i expect to see the polygon even after my loop exceeds 128

Actual result:
--------------
What i can see now is only 128 polygons created perfectly not more than that.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-21 05:37 UTC] swanand dot raikar at gmail dot com
The issue is solved. It was the problem with the code.

i took this line  $bg   = imagecolorallocate($im, 150, 150, 150); outside the function drawPoly(), and everything worked as 

expected.

the new updated code is - 

<?php
$im = imagecreate(600, 400);
$bg   = imagecolorallocate($im, 150, 150, 150);
$x = 20;
$y = 350;
for($i=1;$i<=150;$i++) //create a polygon 128 times
	{
		drawPoly($x,$y,$im);
		$x = $x+2;
		$y = $y-2;
	}
	header('Content-type: image/png');
	imagepng($im);
	imagedestroy($im);	
	function drawPoly($xCoord,$yCoord,$im)
	{
		$x1 = $x2 = $xCoord;
		$x3 = $x4 = $xCoord + 70;
		$y1 = $y4 = $yCoord;
		$y2 = $y3 = $yCoord + 30;
		$Poly = array(0  => $x1,1  => $y1,2  => $x2,3  => $y2,4  => $x3,5  => $y3,6  => $x4,7  => $y4);
		$blue = imagecolorallocate($im, 0, 0, 255);
		imagefilledpolygon($im, $Poly, 4, $blue);
	}
?>

But i still want to know why this happened and why it worked when i took that line outside the function?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 01:01:27 2024 UTC