当前位置:Gxlcms > PHP教程 > php把一个颜色变深的函数

php把一个颜色变深的函数

时间:2021-07-01 10:21:17 帮助过:18人阅读

这个php函数可以把指定的颜色变得更深一些

  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. //范例:
  13. for ($x=1; $x < 20; $x++){
  14. // Start color:
  15. $c = ColorDarken('#FF481D', ($x * 3));
  16. print ".\n";
  17. }

php

人气教程排行