If you like this blog, visit this blog address: blog. csdn. netjunzaivip Overview: gd library drawing: mathematical functions PHP image processing functions use cases 1. verification Code 2. zoom 3. crop 4. watermark gd library drawing: 1. prepare the canvas 2. prepare paint 3. painting 4. output image 5. save image 6. close the canvas? Php Accuracy
If you like this blog, please visit this blog address: http://blog.csdn.net/junzaivip Summary: gd library drawing: mathematical functions PHP image processing function Use Case 1. verification Code 2. zoom 3. crop 4. watermark gd library drawing: 1. prepare the canvas 2. prepare paint 3. painting 4. output image 5. save image 6. close the canvas? Php // quasi
If you like this blog, visit this blog address: http://blog.csdn.net/junzaivip
Summary:
Gd library drawing:
Mathematical functions
PHP image processing functions
Use Cases of image processing functions
1. Verification Code
2. Zoom
3. Crop
4. Watermark
Gd library drawing:
1. Prepare the canvas
2. Prepare paint
3. Painting
4. output image
5. Save the image
6. Close the canvas
PHP image processing functions
1. mathematical functions
2. Image Processing functions
Mathematical functions:
1. max ();
2. min ();
3. mt_rand (); Random Number
Mt_rand random Value
4. ceil (); ceiling
5. floor ();
6. round (); rounding
6. pi (); // π obtain the circumference Rate
Use Cases of image processing functions
1. Verification Code
2. Zoom
3. Crop
4. Watermark
Five steps for wearing an image in PHP
1. Prepare the canvas
2. Prepare paint
3. Draw images or text on the canvas
4. output the final image or caocun final image
5. Release canvas Resources
Image Rendering:
Imagefill ();
Imagesetpixel (); // draw a pixel
Imageline (); // draw a line
Imagerectangle (); // draw a rectangle
Imagepolygon (); // draw a polygon
Imageellipse (); // draw an elliptic
Imageare (); draw an arc
Imagechar (); // draw a character horizontally
Imagestring (); // draw a horizontal string
// Draw a line
// Add interferon
// Draw a rectangle:
// Imagepolygon: polyg_draw a triangle
Draw a 3D pie chart
// Write text:
// Write a single character:
// Write on the Image
PHP verification code design
Php verification code design: two pages are involved: index. php & reg. php
Note:
This verification code version only enables dynamic acquisition of verification Images
The verification code on the front-end registration page is compared with the verification code generated for the image
The verification code is composed of lowercase letters, uppercase letters, and numbers.
Index. php // Implement User Registration
RegUser registration page
Reg. php // used to verify whether the verification code is correct
";// print_r($_SESSION);// echo "
"; $ Vstr = strtolower ($ _ SESSION ['vstr']); if ($ code = $ vstr) {// implement page Jump echo "script location = 'HTTP: // www.baidu.com 'script";} else {echo "script" alert ('verification code input error') script "; // echo" return to the registration page "; echo" script "location = 'index. php 'script ';}?>
Auth. php is used to generate a verification code
Php verification code design:
Page jump:
1. php jump
Header ("location: index. php ");
2. js redirection (recommended)
Echo "script location = 'HTTP: // www.baidu.com 'script";
Echo "script location = 'index. php' script";
Js pop-up window:
Echo 'script alert ("Incorrect verification code, please enter") script ';
2. Zoom
Obtain the width and height of an image.
1. getimagesize (); // you can use the image ("lyf.jpg") to obtain all the information of the image.
2. imagesx (); // to obtain the image width, you must first obtain the image resource (imagecreatefromjpeg ("lyf.jpg");) to obtain the image information.
3. imagesy (); // to get the image height, you must first obtain the image resource to get the image information.
Existing images form canvas resources:
1. imagecreatefromjpeg ();
Method 2: Obtain the image size:
";print_r($imgarr);echo "
"; Exit; $ im = imagecreatefromjpeg (" lyf.jpg "); echo $ x. $ y; header ("content-type: image/jpeg"); imagejpeg ($ im);?>
Image Scaling function:
Imagecopyresampled ();
Proportional scaling of images:
($ Minh/$ maxh) {$ rate = $ minh/$ maxh;} else {$ rate = $ minw/$ maxw ;} $ minw = floor ($ maxw * $ rate); $ minh = floor ($ maxh * $ rate); $ minim = imagecreatetruecolor ($ minw, $ minh ); // scale a large image to a small image imagecopyresampled ($ minim, $ im, 0, 0, 0, 0, $ minw, $ minh, $ maxw, $ maxh ); // The output header of the thumbnail ("content-type: {$ maxm}"); // The Judgment type switch ($ maxt) {case 1: $ imageout = "imagegif"; break; case 2: $ imageout = "imagejpeg"; break; case 3: $ imageout = "Imagepng"; break;} $ imageout ($ minim); $ minfilename = "s _". $ imgfile; $ imageout ($ minim, $ minfilename); // imagejpeg ($ im); // release imagedestroy ($ maxim); imagedestroy ($ minim);?>
Image cropping function:
Imagecopyresampled ();
Image Watermark function:
Imagecopy ();
3. Crop
4. Watermark