I have a script that uploads an image using a form. It creates a preview version of image (width of 500px) and a thumbnail version of the image (width of 100px). But I want all of the thumbnails created be the script to be square, but not distorted, so I need to scale the image so that it maximum dimension is 100 (which I can do) but then I need to crop the other dimension to 100 to make it square (which I can't do). mean?
Does anyone know a script that I can add to my upload script that will crop the image?
Any help is much appreciated, Thanks.
This is my upload script if it helps:
$imagename = $_FILES['new_image']['name'];
$source = $_FILES['new_image']['tmp_name'];
$target = "Images/Photos/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "Images/Photos/Previews/" . $imagepath; //This is the new file you saving
$file = "Images/Photos/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 500;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "Images/Photos/Thumbnails/" . $imagepath; //This is the new file you saving
$file = "Images/Photos/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 100;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;