Home > Backend Development > PHP Tutorial > How to convert a color to its inverse color in php, php converts a color to its inverse color_PHP tutorial

How to convert a color to its inverse color in php, php converts a color to its inverse color_PHP tutorial

WBOY
Release: 2016-07-13 09:56:02
Original
878 people have browsed it

How php converts a color to its inverse color, php converts a color to its

The example in this article describes how php converts a color to its inverse color. Share it with everyone for your reference. The specific analysis is as follows:

This php code can change a color into the opposite color coding, such as: white becomes black, blue becomes yellow

function color_inverse($color){
  $color = str_replace('#', '', $color);
  if (strlen($color) != 6){ return '000000'; }
  $rgb = '';
  for ($x=0;$x<3;$x++){
    $c = 255 - hexdec(substr($color,(2*$x),2));
    $c = ($c < 0) &#63; 0 : dechex($c);
    $rgb .= (strlen($c) < 2) &#63; '0'.$c : $c;
  }
  return '#'.$rgb;
}
//使用范例:
// black -> white
print color_inverse('#000000'); 
// --> returns #ffffff
// blue -> yellow
print color_inverse('#0000FF');
// --> #FFFF00
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/990539.htmlTechArticleHow to convert a color in php to its inverse color, php converts a color to its inverse color. This article explains how to convert a color in php to its inverse color. Inverse color method. Share it with everyone for your reference. The specific analysis is as follows: This paragraph...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template