PHP image processing using imagecopyresampled function clipping picture example, _php tutorial

Source: Internet
Author: User

PHP image processing using the imagecopyresampled function clipping picture example,


Picture clipping refers to a large background image to cut out a specified area of the picture, the common application is when the user set up a profile picture, you can from the uploaded images, cut out a suitable area for their own profile picture. Image cropping is similar to image scaling, so it is also possible to use the imagecopyresampled () function to implement this function. Also in the JPEG image format as an example, declare an image clipping function cut (), the code is as follows:

Copy the Code code as follows:
<?php
Crop a picture of a specified area in a large background image, for example in JPEG image format
function Cut ($filename, $x, $y, $width, $height) {
$back = Imagecreatetruecolor ($width, $height);
Create a resource that can save the cropped picture
$cutimg = Imagecreatetruecolor ($width, $height);
Crop a picture using the imagecopyresampled () function
Imagecopyresampled ($cutimg, $back, 0,0, $x, $y, $width, $height, $width, $height);
Save the cropped picture and prefix the cropped picture if you don't want to overwrite the picture
Imagejpeg ($cutimg, $filename);
Imagedestroy ($CUTIMG);
Imagedestroy ($back);
}

Cut ("Brophp.jpg", 50, 50, 200, 200);
?>

http://www.bkjia.com/PHPjc/914053.html www.bkjia.com true http://www.bkjia.com/PHPjc/914053.html techarticle PHP image processing using the imagecopyresampled function clipping picture example, picture clipping refers to a large background image to cut out a specified area of the picture, the common application is in the user ...

  • 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.