PHP image processing function imagecopyresampled usage explanation

Source: Internet
Author: User
Tags imagejpeg php programming
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.