這幾天做app上傳頭像的功能 發現有的手機拍攝的照片上傳後顯示的圖檔被旋轉了90度
沒辦法弄一下
用metadata-extractor 讀取圖檔的EXIF資訊
https://github.com/drewnoakes/metadata-extractor
例子
public class Zmn {
public static void main(String[] args) throws IOException, ImageProcessingException, MetadataException {
File jpegFile = new File("C:\\Users\\Desktop\\139959356456960.jpg");
Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);
for (Directory directory : metadata.getDirectories()) {
if("Exif IFD0".equals(directory.getName())){
for (Tag tag : directory.getTags()) {
System.out.println(tag +"|"+tag.getTagType());
}
}
}
}
}

讀取出來的資訊就是這個圖檔逆時針旋轉了90度 是以顯示的時候或者存儲的時候順時針旋轉下就行了
用js擷取exif 我用的是這個http://code.ciaoca.com/javascript/exif-js/
随便找的 EXIF.getData(document.getElementById('imgElement'), function(){
EXIF.getAllTags(this);
EXIF.getTag(this, 'Orientation');
});
網站和下載下傳的壓縮包裡都有例子
case 1: return "Top, left side (Horizontal / normal)";
case 2: return "Top, right side (Mirror horizontal)";
case 3: return "Bottom, right side (Rotate 180)";
case 4: return "Bottom, left side (Mirror vertical)";
case 5: return "Left side, top (Mirror horizontal and rotate 270 CW)";
case 6: return "Right side, top (Rotate 90 CW)";
case 7: return "Right side, bottom (Mirror horizontal and rotate 90 CW)";
case 8: return "Left side, bottom (Rotate 270 CW)";
12345678就是這意思 轉的頭暈了。。。休息下