How to rotate JPEG images based on the orientation metadata?

后端 未结 8 1810
轻奢々
轻奢々 2020-11-27 12:30

I have some server code that is generating thumbnails when an image is uploaded. The issue is that when the image was taken and the camera/device was rotated, the thumbnail

8条回答
  •  庸人自扰
    2020-11-27 13:10

    This can be done surprisingly easily by using the image part of JavaXT core library :

    // Browsers today can't handle images with Exif Orientation tag
    Image image = new Image(uploadedFilename);
    // Auto-rotate based on Exif Orientation tag, and remove all Exif tags
    image.rotate(); 
    image.saveAs(permanentFilename);
    

    That's it!

    I have tried Apache Commons Imaging, but that was a mess. JavaXT is way more elegant.

提交回复
热议问题