Code Monkey home page Code Monkey logo

php-rgb-hsl-converter's People

Contributors

mpbzh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

php-rgb-hsl-converter's Issues

Calculation of S in rgb2hsl

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!

Adjustment to $s calculation.

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.

Colors not converting correctly

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.