Posted By

aristoworks on 04/29/09


Tagged

php image cms crop


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

nkrstevski
Dean_IconWeb
sumandahal
aleksanderek
rmmjr


Simple PHP Image Crop


 / Published in: PHP
 

URL: http://www.aristoworks.com

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

  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);

Report this snippet  

You need to login to post a comment.