Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set crop starting position with imgscalr?

I have tried to use imgscalr library with the following crop method:

Scalr.crop(image, height, width);

But it always crops starting at the left upper corner of the image. Can I tweak this behavior to start in the right bottom corner or center?

like image 407
gstackoverflow Avatar asked Dec 08 '14 19:12

gstackoverflow


2 Answers

Definitely - just use the other crop operation that takes x,y,width,height arguments.

like image 158
Riyad Kalla Avatar answered Nov 08 '22 01:11

Riyad Kalla


//center
Scalr.crop(image,
    (image.getWidth() - width) / 2, (image.getHeight() - height) / 2,
    width, height);

//top left:
Scalr.crop(image, width, height);

//top right:
Scalr.crop(image,
    image.getWidth() - width, 0,
    width, height);

//bottom left:
Scalr.crop(image,
    0, image.getHeight() - height,
    width, height);

//bottom right:
Scalr.crop(image,
    image.getWidth() - width, image.getHeight() - height,
    width, height);
like image 2
Viktor Taranenko Avatar answered Nov 08 '22 02:11

Viktor Taranenko