Get color cast using PHP

I want to get a brighter hexadecimal selection of shades from a given hexadecimal value using PHP. For example, I enter the color #cc6699 as input, and I want #ee88aa as the output color. How will I do this in PHP?

+1
source share
4 answers

You need to convert the color to RGB, make additions and convert back:

 // Convert string to 3 decimal values (0-255) $rgb = array_map('hexdec', str_split("cc6699", 2)); // Modify color $rgb[0] += 34; $rgb[1] += 34; $rgb[2] += 17; // Convert back $result = implode('', array_map('dechex', $rgb)); echo $result; 

See here in action .

+7
source

1. divide the color into three elements: cc, 66, 99 2. Convert it to decimal from http://php.net/manual/de/function.hexdec.php 3. Increment three decimal values โ€‹โ€‹4. Convert the decimal to sixth . 5. Put the three elements together

+1
source

Not directly related to your question, but this article is interesting for color conversion: http://beesbuzz.biz/code/hsv_color_transforms.php

0
source

The best solution is to convert RGB to HSL or HSV (just search google for php converter hsl / hsv ).

You can then play with the โ€œlightnessโ€ or โ€œvalueโ€ values โ€‹โ€‹of the color space.

Then convert it back to RGB color space.

0
source

Source: https://habr.com/ru/post/1438057/


All Articles