j3rmain3 Posted November 22, 2006 Share Posted November 22, 2006 i have to use a Color class to change the properties of a graph but i dont really understands graphs very well. I have read the Intro to Classes on the phpfreaks site but applying it to the class i have to use is what im ahving problems with.Here is the class:[code] function Color($red, $green, $blue, $alpha = 0) { $this->red = (int)$red; $this->green = (int)$green; $this->blue = (int)$blue; $this->alpha = (int)round($alpha * 127.0 / 255); $this->gdColor = null; } /** * Get GD color * * @access public * @param $img GD image resource */ function getColor($img) { // Checks if color has already been allocated if(!$this->gdColor) { if($this->alpha == 0 || !function_exists('imagecolorallocatealpha')) $this->gdColor = imagecolorallocate($img, $this->red, $this->green, $this->blue); else $this->gdColor = imagecolorallocatealpha($img, $this->red, $this->green, $this->blue, $this->alpha); } // Returns GD color return $this->gdColor; } }[/code]With the function underneath do i use as:[b]$colour = new Color$colour -> Color("255","0","0",$alpha);[/b][code]function Color($red, $green, $blue, $alpha = 0) { $this->red = (int)$red; $this->green = (int)$green; $this->blue = (int)$blue; $this->alpha = (int)round($alpha * 127.0 / 255); $this->gdColor = null; }[/code]ThanksJ3rmain£ Link to comment https://forums.phpfreaks.com/topic/28082-understanding-classes/ Share on other sites More sharing options...
JasonLewis Posted November 22, 2006 Share Posted November 22, 2006 you have to add a class first....here is what it should look like:[code=php:0]class Color {var $red;var $green;var $blue;var $alpha;var $gdColor; function makeColor($red, $blue, $green, $alpha=""){ $this->red = (int)$red; $this->green = (int)$green; $this->blue = (int)$blue; $this->alpha = (int)round($alpha * 127.0 / 255); $this->gdColor = null; }function getColor($img){ // Checks if color has already been allocated if(!$this->gdColor){ if($this->alpha == 0 || !function_exists('imagecolorallocatealpha')){ $this->gdColor = imagecolorallocate($img, $this->red, $this->green, $this->blue); }else{ $this->gdColor = imagecolorallocatealpha($img, $this->red, $this->green, $this->blue, $this->alpha);} } // Returns GD color return $this->gdColor; } } //end class[/code]then to call it:[code=php:0]$color = new Color;$new_color = $color->("255","0","0",$alpha);[/code] Link to comment https://forums.phpfreaks.com/topic/28082-understanding-classes/#findComment-128472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.