mpbzh / php-rgb-hsl-converter Goto Github PK
View Code? Open in Web Editor NEWConvert RGB to HSL and vice versa.
Home Page: http://michaelburri.ch/generate-different-shades-of-a-color/
License: GNU General Public License v2.0
Convert RGB to HSL and vice versa.
Home Page: http://michaelburri.ch/generate-different-shades-of-a-color/
License: GNU General Public License v2.0
In Line 99 $s is calculated like this:
$s = 1 - abs(2 * $l - 1);
According to Wikipedia S is calculated be dividing Chroma by the therm above. For me changing the line to
$s = $chroma / (1 - abs(2 * $l - 1));
worked out. May somebody can verify this and if it is correct change it for the others.
Thank you in advance and nice software!
Thank you for this marvelous piece of software!
While converting the 141 browser colors, I found that s didn't agree with the results on
http://colorizer.org/ and that they didn't quite look like the hex colors.
It turned out to be the value of s isn't computed correctly for all cases.
https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
Here's the change I made (including the debugging code.)
186 $h = $h_ / 6;
187 //echo(LINE.' $h='.$h.".\n ");
188 //*********************************************************************
189 // https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB ***
190 // Adjustment needed to compute correct value of $s (saturation). ***
191 //*********************************************************************
192 if ($l < 0.5) {
193 $s = ($max-$min)/($max+$min);
194 //echo(LINE.' $s='.$s.".\n");
195 } else {
196 $s = ($max-$min)/(2.0-$max-$min);
198 //echo(LINE.' $s='.$s.".\n");
199 }
The Wikipedia article computes it one way for l < 0.5 and another for l > 0.5.
Nothing for l == 5...artists!
With this small addition, the function returns exactly what colorizer.org does.
I converted cc0000 into hsl then back to hex and the color returned wasn't cc0000. Same thing happened for 003366. It seems like some colors work, but others do not. Maybe a rounding issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.