Page 1 of 1

Best way for dynamic cropping and resizing

Posted: 2007-10-09T13:25:38-07:00
by maffp
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:

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

Image

Image

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!

Re: Best way for dynamic cropping and resizing

Posted: 2007-10-11T08:02:15-07:00
by sevasjack
maffp,
your task is not completely clear. Can you clarify it?

BTW, in PHP exists function proc_open, read about this function more on php.net website, may be it'll help you!
Also there are exists Image Cropper what also can help you. Anyway to crop you should recalculate coordinates of result image and make crop/resize in one command.

Please write more details about your question.

Re: Best way for dynamic cropping and resizing

Posted: 2007-10-11T08:10:42-07:00
by maffp
Hey!

Yeah, I found another javascript image cropper: http://www.defusion.org.uk/code/javascr ... ptaculous/

I set it up so that the marquee had an aspect ratio of 1:1 (square). The javascript then passes the image coordinates to some text inputs which can then be submitted via a form to PHP & Imagemagick. If I can do it as a PHP amateur then I'm sure anyone can but I'm going to post a solution to it for anyone else soon.

Cheers!