In the process of learning PHP will encounter image processing, this article will introduce the method of image processing.
<!--image Processing--
<?php//Picture processing GD2 Profile modification?> <!--draw a picture with image processing function--<?php//$img = Imagecreatetruecolor (500, 500); $red = Imagecolorallocate ($img, 255, 0, 0); $green = imagecolorallocate ($img, 0, 255, 0); $blue = imagecolorallocate ($img, 0, 0, 255); $pur = Imagecolorallocate ($img, 255, 0, 255); $yellow = Imagecolorallocate ($img, 121, 72, 0); Imagefilledrectangle ($img, 0, 0, a, a, $green); Imageline ($img, 0, 0, a, a, $red); Imageline ($img, 0, 0, $blue); Imagefilledellipse ($img, $yellow); Imagefilledellipse ($img, $, $blue); Imagejpeg ($img, ' haha.jpg '); echo " <!--development Verification Code (generate verification code)--<?php check_code (); function Check_code ($width = $height, $num = 4, $type = ' jpeg ') {$img = Imagecreate ($width, $hei Ght); $string = '; for ($i = 0; $i < $num; $i + +) {$rand = Mt_rand (0, 2); Switch ($rand) {case 0: $ascii = Mt_rand (48, 57); Break Case 1: $ascii = Mt_rand (65, 90); Break Case 2: $ascii = Mt_rand (97, 122); Break } $string. = sprintf ('%c ', $ascii); } imagefilledrectangle ($img, 0, 0, $width, $height, randbg ($img)); for ($i = 0; $i < $i + +) {Imagesetpixel ($img, Mt_rand (0, $width), Mt_rand (0, $height), R Andpix ($img)); } for ($i = 0; $i < $num, $i + +) {$x = Floor ($width/$num) * $i + 2; $y = Mt_rand (0, $height-15); Imagechar ($img, 5, $x, $y, $string [$i], Randpix ($img)); } $func = ' image '. $type; $header = ' Content-type:image/'. $type; if (function_exists ($func)) {header ($header); $func ($IMG); }else {echo ' image type not supported '; } Imagedestroy ($IMG); return $string; } function randbg ($img) {return imagecolorallocate ($img, Mt_rand (255), Mt_rand (, 255), Mt_ RAND (130, 255)); } function Randpix ($img) {return imagecolorallocate ($img, Mt_rand (0, +), Mt_rand (0, +), Mt_ra nd (0, 120)); }?> <!--image scaling and trimming technology--<?php $image = imagecreatefrompng (' fbb.png '); $percent = 0.1; List ($width, $height) = getimagesize (' fbb.png '); $new _width = $width * $percent; $new _height = $height * $percent; $new _image = Imagecreatetruecolor ($new _width, $new _height); Imagecopyresampled ($new _image, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height); Header (' Content-type:image/jpeg '); Imagejpeg ($new _image);?> <! --Image watermark processing--<?php $DST = imagecreatefrompng (' https://img.php.cn/upload/course/000/000/002/5833ebba648 Cf229.png '); $SRC = imagecreatefrompng (' https://img.php.cn/upload/course/000/000/002/5833ebe90cc11285.png '); $DST _info = getimagesize (' 5833ebba648cf229.png '); $src _info = getimagesize (' 5833ebe90cc11285.png '); $DST _x = $dst _info[0]-$src _info[0]; $DST _y = $dst _info[1]-$src _info[1]; Imagecopymerge ($DST, $SRC, $dst _x, $dst _y, 0, 0, $src _info[0], $src _info[1], 100); Header (' content-type:image/png '); Imagepng ($DST); Imagedestroy ($DST); Imagedestroy ($SRC);?> <!--make a smart picture watermark function--<?php?>
This article explains the image processing related methods, more relevant content please pay attention to the PHP Chinese network.