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.