private function _allocate_color($color) { if (isset($color["c"])) { $color = cmyk_to_rgb($color); } if (!isset($color[3])) { $color[3] = 0; } list($r, $g, $b, $a) = $color; $r *= 255; $g *= 255; $b *= 255; $a *= 127; $r = $r > 255 ? 255 : $r; $g = $g > 255 ? 255 : $g; $b = $b > 255 ? 255 : $b; $a = $a > 127 ? 127 : $a; $r = $r < 0 ? 0 : $r; $g = $g < 0 ? 0 : $g; $b = $b < 0 ? 0 : $b; $a = $a < 0 ? 0 : $a; $key = sprintf("#%02X%02X%02X%02X", $r, $g, $b, $a); if (isset($this->_colors[$key])) { return $this->_colors[$key]; } if ($a != 0) { $this->_colors[$key] = imagecolorallocatealpha($this->_img, $r, $g, $b, $a); } else { $this->_colors[$key] = imagecolorallocate($this->_img, $r, $g, $b); } return $this->_colors[$key]; }
/** * Allocate a new color. Allocate with GD as needed and store * previously allocated colors in $this->_colors. * * @param array $color The new current color * @return int The allocated color */ private function _allocate_color($color) { if ( isset($color["c"]) ) { $color = cmyk_to_rgb($color); } // Full opacity if no alpha set if ( !isset($color[3]) ) $color[3] = 0; list($r,$g,$b,$a) = $color; $r *= 255; $g *= 255; $b *= 255; $a *= 127; // Clip values $r = $r > 255 ? 255 : $r; $g = $g > 255 ? 255 : $g; $b = $b > 255 ? 255 : $b; $a = $a > 127 ? 127 : $a; $r = $r < 0 ? 0 : $r; $g = $g < 0 ? 0 : $g; $b = $b < 0 ? 0 : $b; $a = $a < 0 ? 0 : $a; $key = sprintf("#%02X%02X%02X%02X", $r, $g, $b, $a); if ( isset($this->_colors[$key]) ) return $this->_colors[$key]; if ( $a != 0 ) $this->_colors[$key] = imagecolorallocatealpha($this->_img, $r, $g, $b, $a); else $this->_colors[$key] = imagecolorallocate($this->_img, $r, $g, $b); return $this->_colors[$key]; }