- <?php
-
- /*
- **************************************************
- Class: ColorAllocator.php
- **************************************************
- Author: Tsiavos Chris <jaames@freemail.gr>
- Date: October 2004
- **************************************************/
-
- /**
- *Allocator for chart colors
- *
- *@author Tsiavos Chris <jaames@freemail.gr>
- *@license http://opensource.org/licenses/gpl-license.php GNU Public License
- */
-
- class ColorAllocator {
-
- const AliceBlue="240,248,255";
- const AntiqueWhite="250,235,215";
- const Aqua="0,255,255";
- const Aquamarine="127,255,212";
- const Azure="240,255,255";
- const Beige="245,245,220";
- const Bisque="255,228,196";
- const Black="0,0,0";
- const BlanchedAlmond="255,235,205";
- const Blue="0,0,255";
- const BlueViolet="138,43,226";
- const Brown="165,42,42";
- const BurlyWood="222,184,135";
- const CadetBlue="95,158,160";
- const Chartreuse="127,255,0";
- const Chocolate="210,105,30";
- const Coral="255,127,80";
- const CornflowerBlue="100,149,237";
- const Cornsilk="255,248,220";
- const Crimson="237,164,61";
- const Cyan="0,255,255";
- const DarkBlue="0,0,139";
- const DarkCyan="0,139,139";
- const DarkGoldenRod="184,134,11";
- const DarkGray="167,167,167";
- const DarkGreen="0,100,0";
- const DarkKhaki="189,183,107";
- const DarkMagenta="139,0,139";
- const DarkOliveGreen="85,107,47";
- const DarkOrange="255,140,0";
- const DarkOrchid="153,50,204";
- const DarkRed="139,0,0";
- const DarkSalmon="233,150,122";
- const DarkSeaGreen="143,188,143";
- const DarkSlateBlue="72,61,139";
- const DarkSlateGray="47,79,79";
- const DarkTurquoise="0,206,209";
- const DarkViolet="148,0,211";
- const DeepPink="255,20,147";
- const DeepSkyBlue="0,191,255";
- const DimGray="105,105,105";
- const DogderBlue="30,144,255";
- const Feldspar="209,146,117";
- const FireBrick="178,34,34";
- const FloralWhite="255,250,240";
- const ForestGreen="34,139,34";
- const Fuchsia="255,0,255";
- const Gainsboro="220,220,220";
- const GhostWhite="248,248,255";
- const Gold="255,215,0";
- const GoldenRod="218,165,32";
- const Gray="190,190,190";
- const Green="0,128,0";
- const GreenYellow="173,255,47";
- const HoneyDew="240,255,240";
- const HotPink="255,105,180";
- const IndianRed="205,92,92";
- const Indigo="75,0,130";
- const Ivory="255,255,240";
- const Khaki="240,230,140";
- const Lavender="230,230,250";
- const LavenderBlush="255,240,245";
- const LawnGreen="124,252,0";
- const LemonChiffon="255,250,205";
- const LightBlue="173,216,230";
- const LightCoral="240,128,128";
- const LightCyan="224,255,255";
- const LightGoldenRodYellow="250,250,210";
- const LightGrey="211,211,211";
- const LightGreen="144,238,144";
- const LightPink="255,182,193";
- const LightSalmon="255,160,122";
- const LightSeaGreen="32,178,170";
- const LightSkyBlue="135,206,250";
- const LightSlateBlue="132,112,255";
- const LightSlateGray="119,136,153";
- const LightSteelBlue="176,196,222";
- const LightYellow="255,255,224";
- const Lime="0,255,0";
- const LimeGreen="50,205,50";
- const Linen="250,240,230";
- const Magenta="255,0,255";
- const Maroon="128,0,0";
- const MediumAquaMarine="102,205,170";
- const MediumBlue="0,0,205";
- const MediumOrchid="186,85,211";
- const MediumPurple="147,112,219";
- const MediumSeaGreen="60,179,113";
- const MediumSlateBlue="123,104,238";
- const MediumSpringGreen="0,250,154";
- const MediumTurquoise="72,209,204";
- const MediumVioletRed="199,21,133";
- const MidnightBlue="25,25,112";
- const MintCream="245,255,250";
- const MistyRose="255,228,225";
- const Moccasin="255,228,181";
- const NavajoWhite="255,222,173";
- const Navy="0,0,128";
- const OldLace="253,245,230";
- const Olive="128,128,0";
- const OliveDrab="107,142,35";
- const Orange="255,165,0";
- const OrangeRed="255,69,0";
- const Orchid="218,112,214";
- const PaleGoldenRod="238,232,170";
- const PaleGreen="152,251,152";
- const PaleTurquoise="175,238,238";
- const PaleVioletRed="219,112,147";
- const PapayaWhip="255,239,213";
- const PeachPuff="255,218,185";
- const Peru="205,133,63";
- const Pink="255,192,203";
- const Plum="221,160,221";
- const PowderBlue="176,224,230";
- const Purple="128,0,128";
- const Red="255,0,0";
- const RosyBrown="188,143,143";
- const RoyalBlue="65,105,225";
- const SaddleBrown="139,69,19";
- const Salmon="250,128,114";
- const SandyBrown="244,164,96";
- const SeaGreen="46,139,87";
- const SeaShell="255,245,238";
- const Sienna="160,82,45";
- const Silver="192,192,192";
- const SkyBlue="135,206,235";
- const SlateBlue="106,90,205";
- const SlateGray="112,128,144";
- const Snow="255,250,250";
- const SpringGreen="0,255,127";
- const SteelBlue="70,130,180";
- const _Tan="210,180,140";
- const Teal="0,128,128";
- const Thistle="216,191,216";
- const Tomato="255,99,71";
- const Turquoise="64,224,208";
- const Violet="238,130,238";
- const VioletRed="208,32,144";
- const Wheat="245,222,179";
- const White="255,255,255";
- const WhiteSmoke="245,245,245";
- const Yellow="255,255,0";
- const YellowGreen="154,205,50";
-
- /**
- *Holds the handlers of the allocated colors. This is useful when a client requests
- *the allocation of a color that is already allocated. In this case no further allocation
- *will occur and the pre-allocated color handler will be returned
- *@access private
- *@var array
- */
- private $AllocatedColors=array();
-
- /**
- *Constructor
- */
- function __construct() { }
-
- /**
- *Allocates the requested color
- *@param mixed $Canvas reference to the image identifier the color will be allocated in
- *@param string $StartColor
- *@param string $FinishColor If $FinishColor is different from $StartColor then a gradient color will be allocated
- */
- public function Allocate(&$Canvas,$StartColor,$FinishColor,$Alpha,$ARange) {
-
- $StartColor_String=constant("ColorAllocator::".$StartColor);
- $FinishColor_String=constant("ColorAllocator::".$FinishColor);
-
- $StartColor_RGB=explode(",",$StartColor_String);
- $FinishColor_RGB=explode(",",$FinishColor_String);
-
- if ($StartColor_String==$FinishColor_String) {
-
- $Red=$StartColor_RGB[0];
- $Green=$StartColor_RGB[1];
- $Blue=$StartColor_RGB[2];
-
- if (array_key_exists("$Red,$Green,$Blue,$Alpha",$this->AllocatedColors))
- return $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"];
- else {
- $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]=ImageColorAllocateAlpha($Canvas,$Red,$Green,$Blue,$Alpha);
- return $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"];
- }
- }
- else {
-
- $RangeY=abs($ARange);
- if ($RangeY==0) $RangeY=1;
-
- $Red_Range=abs($FinishColor_RGB[0]-$StartColor_RGB[0]);
- $Green_Range=abs($FinishColor_RGB[1]-$StartColor_RGB[1]);
- $Blue_Range=abs($FinishColor_RGB[2]-$StartColor_RGB[2]);
-
- $Red_px=$Red_Range/$RangeY;
- $Green_px=$Green_Range/$RangeY;
- $Blue_px=$Blue_Range/$RangeY;
-
- $Red=$FinishColor_RGB[0];
- $Green=$FinishColor_RGB[1];
- $Blue=$FinishColor_RGB[2];
-
- $Colors=array();
-
- for ($i=0;$i<$RangeY;$i++) {
-
- if (array_key_exists("$Red,$Green,$Blue,$Alpha",$this->AllocatedColors))
- array_push($Colors,$this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]);
- else
- {
- $this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]=ImageColorAllocateAlpha($Canvas,round($Red),round($Green),round($Blue),$Alpha);
- array_push($Colors,$this->AllocatedColors["$Red,$Green,$Blue,$Alpha"]);
- }
- if($FinishColor[0]<$StartColor[0]) $Red+=$Red_px;
- else $Red-=$Red_px;
- if($FinishColor[1]<$StartColor[1]) $Green+=$Green_px;
- else $Green-=$Green_px;
- if($FinishColor[2]<$StartColor[2]) $Blue+=$Blue_px;
- else $Blue-=$Blue_px;
-
- }
-
- return $Colors;
- }
-
- }
-
- }
-
- ?>