In PHP, what is the most straightforward way to convert a RGB triplet to HSV values?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- How to get the background from multiple images by
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
Here's my spin on it, along with a unit test. Since the
S
andV
values are percentages, this code returns them as integers (0, 100) as opposed to (0, 1) - Example,75
instead of0.75
.PHPUnit test case with PHP 7.2
Here is a simple, straightforward method that returns HSV values as degrees and percentages, which is what Photoshop's color picker uses.
Note that the return values are not rounded, you can do that yourself if required. Keep in mind that
H(360) == H(0)
, soH
values of359.5
and greater should round to0
Heavily documented for learning purposes.