Return to Snippet

Revision: 13618
at April 29, 2009 10:48 by aristoworks


Initial Code
$file = $_FILES['image']['name'];
$newwidth = 200; // SET YOUR DESIRED WIDTH

			$small_image = str_replace(" ", "_", $file);
			$small_image = "small_".$small_image;
			$smallfile = $_FILES['image']['tmp_name'];
			$src = imagecreatefromjpeg($smallfile);
			list($width,$height)=getimagesize($smallfile);
			$newheight=($height/$width)*$newwidth;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$filename = $imagepath."small/".$small_image;
			imagejpeg($tmp,$filename,100);

			imagedestroy($src);
			imagedestroy($tmp);

Initial URL
http://www.aristoworks.com

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

Initial Title
Simple PHP Image Crop

Initial Tags
php, image

Initial Language
PHP