pChart 2.x forum http://wiki.pchart.net/forum/ |
|
How to fill a specific zone with a color ? http://wiki.pchart.net/forum/viewtopic.php?f=3&t=394 |
Page 1 of 1 |
Author: | Jilimay [ Thu Apr 14, 2011 3:00 pm ] |
Post subject: | How to fill a specific zone with a color ? |
Hi everyone, I am trying to draw a kind of mercury thermometer, very simply created with the mix of a rectangle and circle. I actually have to problems that are almost the same : - First, since my objects are layered, I cannot use transparency properly ; - Second, I would like to fill the thermometer dynamically with two different colors, depending on some parameters (to enable it to play its thermometer's role ^^). So my question is : is there a way to fill in a specific zone of a picture ? Thanks for reading ! |
Author: | jean-damien [ Fri Apr 15, 2011 12:19 pm ] |
Post subject: | Re: How to fill a specific zone with a color ? |
Maybe the drawPolygon function could help you. Transparency will work as you'll only draw one object. JD. |
Author: | Jilimay [ Fri Apr 15, 2011 1:22 pm ] |
Post subject: | Re: How to fill a specific zone with a color ? |
Hi, Thanks for your answer. Actually, I am not sure I am able to draw that kind of things with only one polygon. But I found something that might be interesting with the gd library, the function imagecolorset. But now the question is : is there a way to use these functions with your objects ? Since your work is based on this library ? |
Author: | Jilimay [ Fri Apr 15, 2011 2:04 pm ] |
Post subject: | Re: How to fill a specific zone with a color ? |
Well it seems I got a bit confused, but imagecolorset is used on an existing image, so I can use it as a kind of post-treatment. I think it can be a possible solution. |
Author: | jean-damien [ Fri Apr 15, 2011 2:12 pm ] |
Post subject: | Re: How to fill a specific zone with a color ? |
If you need to access directly the GD image from your script you can use the $myPicture->picture handle : Code: $myPicture = new pImage(100,100); $black = imagecolorallocate($myPicture->picture, 0, 0, 0); imagefilledrectangle($myPicture->picture, 10, 10, 90, 90, $black); $myPicture->picture; $myPicture->autoOutput("picture.png"); |
Author: | Jilimay [ Fri Apr 15, 2011 2:39 pm ] |
Post subject: | Re: How to fill a specific zone with a color ? |
Ok, i assume you're rather talking about $myPicture->Picture ? I tried to do it that way ($myPicture being of course a pImage object) : Code: $color = imagecolorat($myPicture->Picture, 150, 300); imagecolorset($myPicture->Picture, $color, 0, 255, 0); $myPicture->Render("pictures/basic.png"); But the imagecolorset function returns false . What do I get wrong ? |
Author: | Jilimay [ Fri Apr 15, 2011 2:49 pm ] | ||
Post subject: | Re: How to fill a specific zone with a color ? | ||
I am thinking maybe this has to do with my function, so I give you the code in case it's usefull, as well as the picture generated in attachment : Code: function buildThermometer($width=300, $height=600, $ratio=0.5, $goal=0.8) { /* All the pChart classes needed */ require_once("application/third_party/pChart2.1.1/class/pDraw.class.php"); require_once("application/third_party/pChart2.1.1/class/pImage.class.php"); require_once("application/third_party/pChart2.1.1/class/pSurface.class.php"); /* the thermometer to be returned */ $picture = new pImage($width, $height); /* margin if the picture */ $margin = 10; /* transparency */ $alpha = 10; /* * The thermometer is represented thanks to a circle (the basis) * and a rectangle (the pipe). */ /* Circle's caracteristics */ /* the base must be a small part of the thermometre (obviously) */ $cRadius = ($height - 2*$margin ) / 8 ; $cAbs = $width / 2; $cOrd = $height - $margin - $cRadius ; $CircleSettings = array("R"=>209,"G"=>134,"B"=>27,"Alpha"=>$alpha ,"Surrounding"=>30); /* Adding circle to the picture */ $picture->drawFilledCircle($cAbs,$cOrd,$cRadius, $CircleSettings); /* rectangle's caracteristics */ $lAbs = ($width - $cRadius)/2 ; /* left top angle abscissa */ $lOrd = $margin; /* left top angle ordinate */ $rAbs = $width - $lAbs; /* right bottom angle abscissa */ $rOrd = $height - $margin*2; /* right bottom angle ordinate */ $RectangleSettings = array("R"=>209,"G"=>134,"B"=>27, "Alpha"=>$alpha); /* TODO : find how to optimise the radius value for rectangle's corner */ /* Adding rectangle to the picture */ $picture->drawRoundedFilledRectangle($lAbs,$lOrd,$rAbs,$rOrd, 34 ,$RectangleSettings); return $picture; }
|
Author: | Jilimay [ Tue Apr 19, 2011 8:24 am ] |
Post subject: | Re: How to fill a specific zone with a color ? |
Hello again, I haven't found any solution to this issue, even if I believe the trick to be related with the picture's resolution. But I found a way to bypass the problem, by using another function : bool imagefill ( resource $image , int $x , int $y , int $color ). It basically acts like the paint's filling function, and allow me to do what I wanted to. Hope it will help someone else ! |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |