coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.17k stars 789 forks source link

Resizing sideways images applies resize before rotation #91

Closed artichikin closed 2 years ago

artichikin commented 8 years ago

I need to make thumbnails from photos and I don't know in advance if they need rotation or not:

  Thumbnails.of(new FileInputStream(origFile))
        .useExifOrientation(true).outputFormat("jpg")
        .size(280, 360)
        .toFile(thumbFile);

The problem here is if I provide a non-rotated image, it sizes it correctly, and a side-ways oriented image gets scaled to 210 x 280, so it seems like it's calculating the max width and height based on the original dimensions instead of the rotated dimensions?

mdanilakis commented 8 years ago

I think i have a similar problem, the exif orientation is handled properly but the resulting image has black background. I should also note that i use: crop(Positions.CENTER)

camikusch commented 8 years ago

same issue here as artichikin. size(x, y) is applied on the image before its rotated according to EXIF information, leading to a thumbnail that is to small to fit the (x,y) box.

scjnsn commented 7 years ago

Kind of a hack, but to get around this, if the Orientation is not TOP_LEFT or BOTTOM_RIGHT, just swap your width/height parameters. Then it will crop wrong and rotate it back to the right place.

coobird commented 2 years ago

I'll look into this as a candidate to include in an upcoming release.

tuannt39 commented 2 years ago

@coobird same issue Thumbnails.of(bufferedImage).scale(scale).asBufferedImage();

coobird commented 2 years ago

This issue has been fixed in 0.4.18.