Simple PHP Image Crop


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

This is a simple script that will allow you to crop an image that you upload from a form.


Copy this code and paste it in your HTML
  1. $file = $_FILES['image']['name'];
  2. $newwidth = 200; // SET YOUR DESIRED WIDTH
  3.  
  4. $small_image = str_replace(" ", "_", $file);
  5. $small_image = "small_".$small_image;
  6. $smallfile = $_FILES['image']['tmp_name'];
  7. $src = imagecreatefromjpeg($smallfile);
  8. list($width,$height)=getimagesize($smallfile);
  9. $newheight=($height/$width)*$newwidth;
  10. $tmp=imagecreatetruecolor($newwidth,$newheight);
  11. imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
  12. $filename = $imagepath."small/".$small_image;
  13. imagejpeg($tmp,$filename,100);
  14.  
  15. imagedestroy($src);
  16. imagedestroy($tmp);

URL: http://www.aristoworks.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.