Skip to content

Instantly share code, notes, and snippets.

@quisido
Created August 2, 2018 17:11
Show Gist options
  • Save quisido/9d19e29229fd9b89701c5060f89535bc to your computer and use it in GitHub Desktop.
Save quisido/9d19e29229fd9b89701c5060f89535bc to your computer and use it in GitHub Desktop.
Creating a Dynamic Vertical Gradient in PHP
<?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