Best way for dynamic cropping and resizing
Posted: 2007-10-09T13:25:38-07:00
Hi!
I currently have a content management system written in PHP/MySQL. On one page, the administrator is able to upload a picture which is resized to give the image that will be shown:
However, once resized the image is stored, I would also like to create a square 100x100px thumbnail of the image. BUT, this thumbnail may be of all the image or just a small part. E.g.
In either image it may be required to be cropped to the square and then resized to 100x100px.
Is there a way to do this dynamically at upload? Does anyone know of any scripts where the user can, for example, click and drag over an image preview to set the croppable area?
I hope this is at least a little coherent. Cheers!
I currently have a content management system written in PHP/MySQL. On one page, the administrator is able to upload a picture which is resized to give the image that will be shown:
Code: Select all
// Store the orignal file
copy($uploadedPhoto['tmp_name'], $images_dir."/".$filename);
// Get the image size
$size = GetImageSize( $images_dir."/".$filename );
$width = $size[0];
$height = $size[1];
if($width > $height) {
$resize_width = 500;
$resize_height = (int)(500 * $height / $width);
} else {
$resize_width = (int)(500 * $width / $height);
$resize_height = 500;
}
exec("convert $images_dir/$filename -geometry {$resize_width}x{$resize_height} $images_dir/rs_$filename");
In either image it may be required to be cropped to the square and then resized to 100x100px.
Is there a way to do this dynamically at upload? Does anyone know of any scripts where the user can, for example, click and drag over an image preview to set the croppable area?
I hope this is at least a little coherent. Cheers!