How to use PHP & Upload and Resize image The guideline/example scripts how to using PHP and GD , Upload and Resize image
ShotDev Focus:
- PHP & GD (Upload and Resize image)
Example
php_upload_resize1.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form action="php_upload_resize2.php" method="post" enctype="multipart/form-data" name="frmMain"> <table width="343" border="1"> <tr> <td>Upload</td> <td><input name="fileUpload" type="file"></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </body> </html>
php_upload_resize2.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <? if(trim($_FILES["fileUpload"]["tmp_name"]) != "") { $images = $_FILES["fileUpload"]["tmp_name"]; $new_images = "Thumbnails_".$_FILES["fileUpload"]["name"]; copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$_FILES["fileUpload"]["name"]); $width=100; //*** Fix Width & Heigh (Autu caculate) ***// $size=GetimageSize($images); $height=round($width*$size[1]/$size[0]); $images_orig = ImageCreateFromJPEG($images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY); ImageJPEG($images_fin,"MyResize/".$new_images); ImageDestroy($images_orig); ImageDestroy($images_fin); } ?> <b>Original Size</b><br> <img src="<?="MyResize/".$_FILES["fileUpload"]["name"];?>"> <hr> <b>New Resize</b><br> <img src="<?="MyResize/".$new_images;?>"> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_upload_resize1.php
Screenshot
.
.
.
2measurement…
…