-
-
Save codemasher/fb407de5587fdbd3e7c5 to your computer and use it in GitHub Desktop.
Approach to get the right color values from the GW2 colors API like Cliff Spradlin explained here: https://forum-en.guildwars2.com/forum/community/api/API-Suggestion-Colors/2141987
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// functions rgb2hsl and hsl2rgb required | |
// https://gist.github.com/codemasher/741f30e68c6e9c7921c7 | |
// see it live over here: https://chillerlan.net/gw2color.php | |
// example values for "Hot Pink" on cloth, id 126 | |
$b = 14; //brightness | |
$c = 1.21094; //contrast | |
$h = 340; //hue | |
$s = 0.820313; //saturation | |
$l = 1.44531; //lightness | |
// base color | |
$rgb = array(128, 26, 26); | |
// apply brightness and contrast | |
foreach($rgb as $k => $v){ | |
$rgb[$k] = (($v+$b)-128) * $c+128; | |
} | |
// convert to HSL | |
$hsl = rgb2hsl($rgb); | |
// apply shifts | |
$hsl[0] = ($hsl[0]*360+$h)/360; | |
$hsl[1] = $hsl[1]*$s; | |
$hsl[2] = $hsl[2]*$l; | |
// convert back to RGB | |
$rgb = hsl2rgb($hsl); | |
// round RGB values | |
foreach($rgb as $k => $v){ | |
$rgb[$k] = round($v); | |
// "correct" values to be in range 0-255 according to | |
// https://forum-en.guildwars2.com/forum/community/api/How-To-Colors-API/2146224 | |
if($rgb[$k]<0){$rgb[$k] = 0;} | |
if($rgb[$k]>255){$rgb[$k] = 255;} | |
} | |
// final RGB value | |
print_r($rgb); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment