public static function ImageHue(&$image, $hue, $saturation) { $width = imagesx($image); $height = imagesy($image); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $rgb = imagecolorat($image, $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; $alpha = ($rgb & 0x7f000000) >> 24; $hsl = ColorUtils::rgb2hsl(array('r' => $r, 'g' => $g, 'b' => $b)); $h = $hsl['h'] / 360; $s = $hsl['s'] / 100; $h += $hue / 360; $s += $saturation / 100; if ($h > 1) { $h--; } if ($s > 1) { $s--; } $hsl['h'] = $h * 360; $hsl['s'] = $s * 100; $rgb = ColorUtils::hsl2rgb($hsl); imagesetpixel($image, $x, $y, imagecolorallocatealpha($image, $rgb['r'], $rgb['g'], $rgb['b'], $alpha)); } } }
/** * Converts a hsl color to it's hex equivalent * @param array $hsl * @return string The hex string */ public static function hsl2hex($hsl) { $rgb = ColorUtils::hsl2rgb($hsl); return ColorUtils::rgb2hex($rgb); }