red = $red; $this->green = $green; $this->blue = $blue; $this->alpha = $alpha; } /** * @param resource $image GD image resource * @return int Returns the index of the specified color+alpha in the palette of the image, * or -1 if the color does not exist in the image's palette. */ public function getIndex($image) { if ($this->hasAlphaChannel()) { return imagecolorexactalpha( $image, $this->red, $this->green, $this->blue, $this->alpha ); } else { return imagecolorexact( $image, $this->red, $this->green, $this->blue ); } } /** * @return bool TRUE when alpha channel is specified, FALSE otherwise */ public function hasAlphaChannel() { return $this->alpha !== null; } }