Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crop method usage to examples #211

Open
aalster opened this issue Nov 22, 2023 · 2 comments
Open

Add crop method usage to examples #211

aalster opened this issue Nov 22, 2023 · 2 comments
Assignees

Comments

@aalster
Copy link

aalster commented Nov 22, 2023

It is a common use-case to crop an image to fit thumbnail size without leaving the gaps on sides. Currently examples page says

NOTE: Using this approach, the thumbnail will not necessarily be 200 pixel by 200 pixel dimensions

but doesn't provide a solution to force size keeping original aspect ratio.

Please add this example to Forcing thumbnails to be exactly the specified size section:

BufferedImage originalImage = ImageIO.read(new File("original.png"));

BufferedImage thumbnail = Thumbnails.of(originalImage)
        .crop(Positions.CENTER)
        .size(200, 200)
        .asBufferedImage();

This is a great feature of library but it is not easy to spot. Initially I was calculating sizes myself which required me to read bytes as BufferedImage to get original image size and then read bytes second time to make library determine output format automatically.

@coobird
Copy link
Owner

coobird commented Dec 16, 2023

Thank you for the suggestion! That's a great idea!

@coobird coobird self-assigned this Dec 16, 2023
@sparkwan
Copy link

sparkwan commented Jan 8, 2024

I also need this feature @coobird.
Another feature: crop an transparent/white backgroud image automatically using a specify margin at orignal aspect ratio? The basic idea is that to find the start and end of X/Y cordinate by comparing pixel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants