- $src _path = ' 1.jpg ';
- Create a source diagram instance
- $SRC = imagecreatefromstring (file_get_contents ($src _path));
- Crop the coordinates of the point in the upper-left corner of the open area
- $x = 100;
- $y = 12;
- Width and height of clipping area
- $width = 200;
- $height = 200;
- Finally save the width and height of the picture, and the source to equal proportions, otherwise it will deform
- $final _width = 100;
- $final _height = Round ($final _width * $height/$width);
- Copy the cropping area to a new picture and zoom in or out based on the width of the source and destination
- $new _image = Imagecreatetruecolor ($final _width, $final _height);
- Imagecopyresampled ($new _image, $src, 0, 0, $x, $y, $final _width, $final _height, $width, $height);
- Output picture
- Header (' Content-type:image/jpeg ');
- Imagejpeg ($new _image);
- Imagedestroy ($SRC);
- Imagedestroy ($new _image);
Copy CodePicture after cropping: In fact, if the coordinates are (0,0), the width and height of the cropping area are consistent with the width of the source graph, then it is the function of generating thumbnails. The above is only the example of the PHP cropped image, which belongs to the function of the server. If the client needs, you can use jquery plug-in imageareaselect, good compatibility. |