Closed BaolCristian closed 10 months ago
Inspecting with exiftools shows that orientation information is removed as a result.
@BaolCristian, the issue here is that the JPEG file has Exif metadata that contains the orientation information, so the original pixels stored in the image is actually rotated, as seen in the image shrunken by Thumbnailator.
The reason for this is that you're reading the image to a BufferedImage
before handing it to Thumbnails.of
. Thumbnailator will detect the Exif metadata and apply proper rotation to give the correct orientation as long as the JPEG file is given to Thumbnails.of
.
Therefore, if the code was rewritten as:
InputStream is = new BufferedInputStream(img.getBinaryStream())
def result=Thumbnails.of(is).size(600, 600).asBufferedImage()
This should end up with the correct orientation for the thumbnail.
I will be closing this issue as a resolution has been provided.
Expected behavior
Please describe what you are expecting the library to perform. When I resize an image I don't want rotation
Actual behavior
Please describe the actual behavior you are experiencing, including stack trace and other information which would help diagnose the issue. The image is rotated (sometimes +90°, sometimes -90°)
Steps to reproduce the behavior
Please enter step-by-step instructions for reproducing the actual behavior. Including code can be helpful in diagnosing issue, but please keep the code to a minimal that will reproduce the behavior. InputStream is = new BufferedInputStream(img.getBinaryStream()) BufferedImage bi = ImageIO.read(is); def result=Thumbnails.of(bi).size(600, 600).asBufferedImage()
Environment
Please provide vendor and version information for the Operating System, JDK, and Thumbnailator. Please feel free to add any other information which may be pertinent.
I'm using GRAILS 4.0.1
Try with this image:![thumbnail_doc01756120221219103145_001](https://user-images.githubusercontent.com/34384527/220173142-7ebecd53-0ebe-462f-a209-36c5ca96d5fe.jpg)
Result