1 ? $vh - 1 : $vh); if ($vh * 6 < 1) { return $v1 + ($v2 - $v1) * 6 * $vh; } if ($vh * 2 < 1) { return $v2; } if ($vh * 3 < 2) { return $v1 + ($v2 - $v1) * ((2 / 3) - $vh) * 6; } return $v1; } /** * Convert strings like "64M" or "30" to int values * @param mixed $size * @return int */ public static function normalizeInt($size) { if (is_string($size)) { $letter = substr($size, -1); $size = intval($size); switch ($letter) { case 'M': case 'm': return (int) $size * 1048576; case 'K': case 'k': return (int) $size * 1024; case 'G': case 'g': return (int) $size * 1073741824; } } return (int) $size; } /** * Converts a string containing and RGB percentage value into a RGB integer value i.e. '90%' -> 229.5 * @param $rgbPercentage * @return int */ public static function rgbPercentageToRgbInteger($rgbPercentage) { if (strpos($rgbPercentage, '%') !== false) { $rgbPercentage = self::roundNumber(floatval(str_replace('%', '', $rgbPercentage)) * 2.55); } return intval($rgbPercentage, 10); } /** * Converts a RGB color into a HEX color * @param array $rgbColors * @return array */ public static function rgbToHex($rgbColors) { $hexColors = array(); // Values outside the sRGB color space should be clipped (0-255) for ($i = 0, $l = count($rgbColors); $i < $l; $i++) { $hexColors[$i] = sprintf("%02x", self::clampNumberSrgb(self::rgbPercentageToRgbInteger($rgbColors[$i]))); } return $hexColors; } /** * Rounds a number to its closest integer * @param $n * @return int */ public static function roundNumber($n) { return intval(round(floatval($n)), 10); } }