This article mainly introduces the implementation of PHP anti-color processing of the image, involving PHP for image reading, numerical operations and other related operations skills, the need for friends can refer to the following
In this paper, we describe the anti-color processing function of PHP for image. Share to everyone for your reference, as follows:
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 ~):
Articles you may be interested in:
PHP tips for installing extensions by using the Pecl method
PHP tips for mb_strstr basic PHP Learning Notes
PHP deletes an array of elements specified in the subscript method PHP instance