This time to everyone to bring PHP implementation of the image of the anti-color processing steps, PHP implementation of the image of the anti-color processing of the attention of the matter, the following is the actual case, a look.
Today, there is a need to use PHP to color the picture, and turn gray, before I did not know is not feasible, and then saw the imagefilter()
function, used to turn gray more than enough, good strong;
ImageFilter ($im, Img_filter_grayscale)
Of course, there are people in CSS to set the gray
<style type= "Text/css" >img {-webkit-filter:grayscale (1);/* WebKit */filter:gray;/* ie6-9 */filter:grayscale (1) ; * * */}</style>
PHP color code:
<?php/*** is mainly used for image processing function *///image inverse color function color ($url) {//Get picture Information list ($width, $height, $type, $attr) = GetImageSize ( $url); $imagetype = Strtolower (Image_type_to_extension ($type, false)); $fun = ' Imagecreatefrom '. ($imagetype = = ' jpg '? ') JPEG ': $imagetype); $img = $fun ($url); for ($y =0; $y < $height; $y + +) {for ($x =0; $x < $width; $x + +) {//Get the value of the color $index = Imagecolorat ( $img, $x, $y); Gets an array of colors $color = Imagecolorsforindex ($img, $index); The inverse of the color value $red = 256-$color [' Red ']; $green = 256-$color [' Green ']; $blue = 256-$color [' Blue ']; $hex = Imagecolorallocate ($img, $red, $green, $blue); Assigns a color value to each pixel Imagesetpixel ($img, $x, $y, $hex); }}//Output picture switch ($imagetype) {case ' gif ': imagegif ($img); Break Case ' JPEG ': imagejpeg ($img); Break Case ' png ': imagepng ($img); Break Default:break; }}
Test code:
$imgurl = ' 1.jpg '; echo color ($imgurl);
The original picture (in the small series commonly used in the destruction of childhood spoof diagram for example):
After the operation (here to test-oriented, as for the image of the three-view subversion or facial features, small series will not ask the ~):
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
PHP implementation parsing XML and generating SQL statement steps in detail
PHP implementation of regular expression grouping capture steps in detail