Php: how to modify the size of the uploaded image. _ PHP Tutorial

Source: Internet
Author: User
Php modifies the size of the uploaded image ,. Php modifies the size of the uploaded image. This document describes how php modifies the size of the uploaded image. Share it with you for your reference. The specific implementation method is as follows: phpThisisthet php modifies the size of the uploaded image,

This example describes how to modify the size of an uploaded image in php. Share it with you for your reference. The specific implementation method is as follows:

<?php// This is 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 imagelist($width,$height)=getimagesize($uploadedfile);// For our purposes, I have resized the image to be// 600 pixels wide, and maintain the original aspect// ratio. This prevents the image from being "stretched"// or "squashed". If you prefer some max width other than// 600, 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 imageimagecopyresampled($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 will clean up the temp file it created when the request// has completed.?>

I hope this article will help you with php programming.

The example in this article describes how to modify the size of the uploaded image in php. Share it with you for your reference. The specific implementation method is as follows: php // This is the t...

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.