ITwebinfo.com - resizing jpeg image


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?
  2.  
  3. /*this can be used to resize image in jpeg format only
  4. which provive a good quality thumbnails*/
  5. // This is the temporary file created by PHP
  6.  
  7. $uploadedfile = $_FILES['simage']['tmp_name'];
  8.  
  9. // Create an Image from it so we can do the resize
  10. $src = imagecreatefromjpeg($uploadedfile);
  11.  
  12. // Capture the original size of the uploaded image
  13. list($width,$height)=getimagesize($uploadedfile);
  14. $newwidth=300;
  15. //$newheight=($height/$width)*100;
  16. $newheight=200;
  17. $tmp=imagecreatetruecolor($newwidth,$newheight);
  18.  
  19. // this line actually does the image resizing, copying from the original
  20. // image into the $tmp image
  21. imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
  22.  
  23. // now write the resized image to disk. I have assumed that you want the
  24. // resized, uploaded image file to reside in the ./images subdirectory.
  25. $filename = $_FILES['simage']['name'];
  26. imagejpeg($tmp,$filename,100);
  27.  
  28. ?>

URL: http://www.itwebinfo.com/forum/comments.php?DiscussionID=4&page=1#Item_0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.