Crop a picture PHP code

Source: Internet
Author: User

The following example cuts the 100x100 portion of the upper-left corner of the picture. You can modify the clipping range by modifying $src_x, $src _y, $src _w, $src the value of _h.

    1. $filename = "Test.jpg";
    2. List ($w, $h, $type, $attr) = getimagesize ($filename);
    3. $src _im = Imagecreatefromjpeg ($filename);
    4. $src _x = ' 0 '; Begin X
    5. $src _y = ' 0 '; Begin Y
    6. $src _w = ' 100 '; Width
    7. $src _h = ' 100 '; Height
    8. $DST _x = ' 0 '; Destination X
    9. $dst _y = ' 0 '; Destination y
    10. $DST _im = Imagecreatetruecolor ($src _w, $src _h);
    11. $white = Imagecolorallocate ($dst _im, 255, 255, 255);
    12. Imagefill ($dst _im, 0, 0, $white);
    13. Imagecopy ($dst _im, $src _im, $dst _x, $dst _y, $src _x, $src _y, $src _w, $src _h);
    14. Header ("Content-type:image/png");
    15. Imagepng ($dst _im);
    16. Imagedestroy ($dst _im);
    17. ?>
Copy Code

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