Home >Backend Development >PHP Tutorial >PHP function that darkens a color

PHP function that darkens a color

WBOY
WBOYOriginal
2016-07-25 08:45:271087browse

This php function can make the specified color darker

  1. function ColorDarken($color, $dif=20){
  2. $color = str_replace('#', '', $color);
  3. if (strlen($color) != 6){ return '000000'; }
  4. $rgb = '';
  5. for ($x=0;$x<3;$x++){
  6. $c = hexdec(substr( $color,(2*$x),2)) - $dif;
  7. $c = ($c < 0) ? 0 : dechex($c);
  8. $rgb .= (strlen($c) < 2) ? '0'.$c : $c;
  9. }
  10. return '#'.$rgb;
  11. }
  12. //Example:
  13. for ($x=1; $x < 20; $x++) {
  14. // Start color:
  15. $c = ColorDarken('#FF481D', ($x * 3));
  16. print "
    .
    n";
  17. }
Copy code

php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn