The example of PHP image processing function imagecopyresampled usage is described in this paper. Share to everyone for your reference, as follows:
Grammar
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
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
I hope this article is helpful to you in PHP programming.