Crop without resize

See all posts Reply

Crop without resize new!
by Mathijs, 14 years, 7 months ago
Hi Colin,

Is it possible to just crop an image to a certain size with the original size being variabel.

So let's say i upload a picture of 800x600 and 1280x1024
The class creates a thumbnail of 100x100 of both files, without resizing, but just cropping.Reply
Re: Crop without resize new!
by colin, 14 years, 7 months ago
You can do this indirectly: you can read image_src_x and image_src_y before calling process(), and act accordingly. For instance (not tested):
// the size you want
$my_x = 100;
$my_y = 100;
// the margins you will have to crop
$crop_x = (int) (($handle->image_src_x - $my_x) / 2);
$crop_y = (int) (($handle->image_src_y - $my_y) / 2);
// we set the cropping values
$handle->image_crop = array($crop_y, $crop_x, $crop_y, $crop_x);
// and call process()
$handle->process(...);
Reply