Use the gd library to crop and generate thumbnails on the php server. Cropping example: The final cropped image. in the dotted box, the cropped image is saved as a 100-width image. The code is as follows: Copy the code as follows: $ src_path cropping example:
The final cropped image:
In the dotted box, the cropped image is saved as a 100-width image. The code is as follows:
The code is as follows:
$ Src_path = '1.jpg ';
// Create an instance of the source image
$ Src = imagecreatefromstring (file_get_contents ($ src_path ));
// Crop the coordinates of the points in the upper left corner of the area.
$ X = 100;
$ Y = 12;
// Width and height of the cropping area
$ Width = 200;
$ Height = 200;
// The image is saved to the width and height of the image, and the source-to-source ratio. Otherwise, the image will be deformed.
$ Final_width = 100;
$ Final_height = round ($ final_width * $ height/$ width );
// Copy the cropping area to the new image and scale or pull the image up or down based on the width and height of the source and target.
$ New_image = imagecreatetruecolor ($ final_width, $ final_height );
Imagecopyresampled ($ new_image, $ src, 0, 0, $ x, $ y, $ final_width, $ final_height, $ width, $ height );
// Output image
Header ('content-Type: image/jpeg ');
Imagejpeg ($ new_image );
Imagedestroy ($ src );
Imagedestroy ($ new_image );
In fact, if the coordinates are (0, 0), the width and height of the cropping area are the same as those of the source image, then the thumbnail is generated.
Summary
Only examples of php cropping images are listed here, which are server-side functions. If the client needs it, we recommend a jquery plug-in imageAreaSelect with excellent compatibility.
Crop the final cropped image: the image to be cropped is saved as a 100-width image in the dotted box. The code is as follows: $ src_path...