How to set crop starting position with imgscalr?

1.7k views Asked by At

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?

2

There are 2 answers

1
Riyad Kalla On BEST ANSWER

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

0
Viktor Taranenko On
//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);