coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.14k stars 784 forks source link

useExifOrientation flag is not respected for BufferedImage #136

Closed KamilKrol closed 4 years ago

KamilKrol commented 5 years ago

Expected behavior

When setting useExifOrientation flag to true, one can expect that Image orientation is handled properly no matter what Image source we use (InputStream, BufferedImage etc.).

Actual behavior

Image orientation from EXIF metadata is respected in other cases. After checking the source code it seems that:

Steps to reproduce the behavior

Test cases reproducing the issue: https://github.com/KamilKrol/thumbnailator/commit/d839bb977c2102637db121ce5401d077c7689266 For the moment we have implemented workaround in our application, but we need to implement proper solution - ideally by providing Pull request to this library.

Environment

Should be reproducible on any environment (implementation problem).

coobird commented 4 years ago

Exif is metadata contained in image streams that support including Exif metadata. A BufferedImage is an Java class which is essentially a buffer containing image data. BufferedImage is not a image format but rather a container for handling image data in Java, and does not include Exif metadata.

Since BufferedImage does not include Exif data, it is not possible to use it to determine orientation of a BufferedImage since it doesn't exist. Basically, the moment you read the image stream to a BufferedImage the Exif metadata is lost. Therefore, this behavior is expected.