Created
August 2, 2018 17:11
-
-
Save quisido/9d19e29229fd9b89701c5060f89535bc to your computer and use it in GitHub Desktop.
Creating a Dynamic Vertical Gradient in PHP
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 | |
// gradient with 10px height | |
$height = 10; | |
// start color is #fa0000 | |
$start = Array(250, 0, 0); | |
// end color is #00c864 | |
$end = Array(0, 200, 100); | |
/* | |
Each pixel's RED value needs to be 25 shades LIGHTER than the last. | |
Each pixel's GREEN value needs to be 20 shades DARKER than the last. | |
Each pixel's BLUE value needs to be 10 shades DARKER than the last. | |
*/ | |
$step = Array(-25, 20, 10); | |
/* | |
After 10 steps, | |
RED will be 250 + -25 * 10 = 0 | |
GREEN will be 0 + 20 * 10 = 200 | |
BLUE will be 0 + 10 * 10 = 100 | |
The magic of algorithm: | |
$start[$x] + $step[$x] * $height = $end[$x] | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment