protected function color(array $color, $image = false) { if (!is_array($image)) { $image = $this->map; } list($r, $g, $b) = $color; $colorRes = imagecolorexact($image['image'], $r, $g, $b); if ($colorRes == -1) { $colorRes = imageColorAllocate($image['image'], $r, $g, $b); if (!$colorRes) { $colorRes = imageColorClosest($image['image'], $r, $g, $b); } } return $colorRes; }
$lightBorder['b'] = $fill['b'] + $step; if($lightBorder['b'] > 255){ $lightBorder['b'] = 255; } // For now, all borders are dark //$lightBorder = "000000"; $darkBorder = "000000"; $image = imageCreateFromPNG($iconDirectoryPath . $iconName); $phpFillIndex = imageColorClosest($image,$existingFill['r'],$existingFill['g'],$existingFill['b']); imageColorSet($image,$phpFillIndex,$fill['r'],$fill['g'],$fill['b']); $phpDarkBorderIndex = imageColorClosest($image,$existingDarkBorder['r'],$existingDarkBorder['g'],$existingDarkBorder['b']); imageColorSet($image,$phpDarkBorderIndex,$darkBorder['r'],$darkBorder['g'],$darkBorder['b']); $phpLightBorderIndex = imageColorClosest($image,$existingLightBorder['r'],$existingLightBorder['g'],$existingLightBorder['b']); imageColorSet($image,$phpLightBorderIndex,$lightBorder['r'],$lightBorder['g'],$lightBorder['b']); header('Content-type: image/png'); imagePNG($image); imageDestroy($image); /** * @param $hex string 6-digit hexadecimal color * @return array 3 elements 'r', 'g', & 'b' = int color values * @desc Converts a 6 digit hexadecimal number into an array of * 3 integer values ('r' => red value, 'g' => green, 'b' => blue) */ function hex2int($hex) { return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits
/** * Create a color resource using an RGB array * * @param array $color array(1,2,3) of RGB calues * @param array[optional] $image The image to allocate for (map is default) * * @return GD color resource */ protected function color(array $color, $image = false) { if (!is_array($image)) { $image = $this->map; } list($r, $g, $b) = $color; // Try to allocate the color from the palette .. $colorRes = imagecolorexact($image['image'], $r, $g, $b); if ($colorRes == -1) { // .. if the color doesn't exist within the palette add it to the palette (which can hit a limit if the palette gets full) .. $colorRes = imageColorAllocate($image['image'], $r, $g, $b); if (!$colorRes) { // .. and failing that get the best available thing. $colorRes = imageColorClosest($image['image'], $r, $g, $b); } } return $colorRes; }