PHP Modify the Upload image size method _php

Source: Internet
Author: User
This article explains how PHP modifies the size of the uploaded image. Share to everyone for your reference. The implementation method is as follows:

<?php//the temporary file created by Php$uploadedfile = $_files[' UploadFile ' [' Tmp_name '];//Create an Image f Rom it so we can do the RESIZE$SRC = Imagecreatefromjpeg ($uploadedfile);//Capture The original size of the uploaded image List ($width, $height) =getimagesize ($uploadedfile),//For our purposes, I has resized the image to be//pixels wide, an D maintain the original aspect//ratio. This prevents the image from being "stretched"//or "squashed". If you prefer some max width other than//, simply change the $newwidth variable$newwidth=600; $newheight = ($height/$widt h) *600; $tmp =imagecreatetruecolor ($newwidth, $newheight);//This line actually does the image resizing, copying from the OR iginal//image into the $tmp imageimagecopyresampled ($tmp, $SRC, 0,0,0,0, $newwidth, $newheight, $width, $height);//Now Write the resized image to disk. I have assumed this want the//resized, uploaded image file to reside in the./images subdirectory. $filename = "Images /". $_files[' UploAdfile ' [' Name '];imagejpeg ($tmp, $filename, +), Imagedestroy ($SRC); Imagedestroy ($tmp);//note:php'll clean up the Temp file It created when the request//have completed.? >

I hope this article is helpful to everyone's PHP programming.

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