PHP Modify upload picture size method _php Tips

Source: Internet
Author: User
Tags php programming

This article illustrates how PHP modifies the size of an uploaded image. Share to everyone for your reference. The implementation method is as follows:

<?php//This are the temporary file created by php $uploadedfile = $_files[' UploadFile '] [' tmp_name '];
Create an Image from it so we can do the resize $src = Imagecreatefromjpeg ($uploadedfile);
Capture the original size of the uploaded image list ($width, $height) =getimagesize ($uploadedfile); For we purposes, I have resized the image to be/pixels wide, and maintain the original aspect//ratio. This prevents the image from being "stretched"//or "squashed".
If you are prefer some max width other than//, simply change the $newwidth variable $newwidth = 600;
$newheight = ($height/$width) *600;
$tmp =imagecreatetruecolor ($newwidth, $newheight); This line actually does the image resizing copying from the original//image into the $tmp image imagecopyresampled ($
TMP, $SRC, 0,0,0,0, $newwidth, $newheight, $width, $height); Now write the resized image to disk.
I have assumed that you want the//resized, uploaded image file to reside in the./images subdirectory. $filename = "ImAges/".
$_files[' UploadFile ' [' name '];
Imagejpeg ($tmp, $filename, 100);
Imagedestroy ($SRC);
Imagedestroy ($TMP);
Note:php'll clean up the temp file it created the request//has completed. ?>

I hope this article will help you with your 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.