This article mainly introduced the PHP image processing function imagecopyresampled usage, combined with the instance form detailed analysis imagecopyresampled function's function, the parameter, the use method, the need friend can refer to the next
Grammar
Copy the Code code as follows:
BOOL Imagecopyresampled (Resource $DST _image, resource $src _image, int $dst _x, int $dst _y, int $src _x, int $src _y, int $DST _w, int $dst _h, int $src _w, int $src _h)
Parameters
Dst_image |
Target Image connection resource. |
Src_image |
Source Image Connection resource. |
Dst_x |
The target X coordinate point. |
Dst_y |
The target Y-coordinate point. |
Src_x |
The X-coordinate point of the source. |
Src_y |
The Y-coordinate point of the source. |
Dst_w |
The target width. |
Dst_h |
Target height. |
Src_w |
The width of the source image. |
Src_h |
The height of the source image. |
Returns TRUE on success, or FALSE on failure.
Case
Case (Image cut):
<?php $targ _w = $targ _h = 150;//Set Target width and height $jpeg _quality = 90;//Picture quality 90, out of $src = ' demo_files/pool.jp G '; Processed picture $img _r = Imagecreatefromjpeg ($SRC);//Get original $dst _r = Imagecreatetruecolor ($targ _w, $targ _h);//Get new diagram
imagecopyresampled ($dst _r, $img _r,0,0,$_post[' x '],$_post[' y '], $targ _w, $targ _h,$_post[' W '],$_post[' h ']); Target map source map target x coordinate point target y coordinate point source X coordinate point source y coordinate points target width target height source graph width Source Graph height header (' content-type:image/jpeg '); Imagejpeg ($dst _r,null, $jpeg _quality); Output image to browser or file?>
Case Two (resampling):
<?php//source file $filename = ' 1.jpg ';//Set maximum width and height $width = n; $height = 400;//Content typeheader (' content-type:image/jpeg '); /Get new Size list ($width _orig, $height _orig) = getimagesize ($filename); $ratio _orig = $width _orig/$height _orig;if ($width/$ Height > $ratio _orig) { $width = $height * $ratio _orig;} else { $height = $width/$ratio _orig;} resampling $image_p = Imagecreatetruecolor ($width, $height); $image = Imagecreatefromjpeg ($filename); Imagecopyresampled ($ Image_p, $image, 0, 0, 0, 0, $width, $height, $width _orig, $height _orig);//Output imagejpeg ($image _p, NULL, 100);? >
Three ways to upload images are attached
1. Select picture, submit form, Server unified processing upload, save path
2. Select picture, upload, get path, submit form, save path
3. Select the image, upload to the server, get a picture of the server in some way, save to local
The above is the whole content of this article, I hope that everyone's study has helped.