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 hex color (0x######) to it's hsl equivalent * @param int $hex * @return array (h,s,l) */ public static function hex2hsl($hex) { return ColorUtils::rgb2hsl(ColorUtils::hex2rgb($hex)); }