I have a script for uploading photos and it also creates a thumbnail.

I haven't written this script. I've just been using it and somewhat adapted it to work with my page. In this case it's just updating(can be adding too) a photo for members.

I dont' like the thumbnail feature. First it doesn't work 100% with the width and height(don't know why).
And I don't like how (when you set a height and width for the thumbnail) the photos dont' have the correct proportions.

I would like to crop the thumbnail instead, so that it at least has the right proportion. Square format(kind of like on facebook) would probably be best to fit all kinds of photo layouts.

Is it possible to add this(a cropping feature) to the code below. Also is it difficult to get it to work with other images than JPEG..........like PNG and GIF?

Would be grateful for info about this


PHP Code:
if ($_FILES["thefile"]["type"] != "image/pjpeg" AND $_FILES["thefile"]["type"] != "image/jpeg" AND $_FILES["thefile"]["type"] != ""

header("Location: error_filetype.php");

$max '75000'
$file_size $_FILES['thefile']['size']; 

if (
$file_size $max

header("Location: error_filesize.php");

// Upload File To Web Server
$pPath "photos/"

if (
move_uploaded_file($_FILES['thefile']['tmp_name'], $pPath.$_FILES['thefile']['name']) or die ("CouldnĄt copy");

header("Location: members.php");

// Define the file
$filename $pPath.$_FILES['thefile']['name'];
$thumbname "TN_".$_FILES['thefile']['name'];
$thumbnail $pPath.$thumbname;

// Set a maximum height and width
$width $Photo_Width;
$height $Photo_Height;

// Determine File Name
$myfilename substr($filename3);
$mythumbname substr($thumbnail3);

//Create INSERT query
$qry "UPDATE members SET content='$content', photo_path='$myfilename', thumb_path='$mythumbname' WHERE member_id='$member_id'";
$result mysql_query($qry) or die("Query failed"); 

// Get new dimensions
list($width_orig$height_orig) = getimagesize($filename);

if (
$width && ($width_orig $height_orig)) {
$per =  (100*$width)/$width_orig;
$per round($per);
$height = ($height_orig*$per)/100;
//($height / $height_orig) * $width_orig;
if ($width 100){
$pre 100 $width;
$width $width $pre;
//echo $width;
    if (
$width 100){
$pre $width 100;
$width $width $pre;
//echo $pre;
} else {
$height = ($width $width_orig) * $height_orig;

// Resample
$image_p imagecreatetruecolor($width$height);
$image imagecreatefromjpeg($filename);

// Output
$pasto getimagesize($pPath.$thumbname);
$user 1;
$elwidth $pasto[0];
$elheight $pasto[1];
} else {