Accessing JPEG EXIF rotation data in JavaScript on the client side

前端 未结 8 1552
臣服心动
臣服心动 2020-11-22 13:53

I\'d like to rotate photos based on their original rotation, as set by the camera in JPEG EXIF image data. The trick is that all this should happen in the browser, using Jav

8条回答
  •  误落风尘
    2020-11-22 14:24

    You can use the exif-js library in combination with the HTML5 File API: http://jsfiddle.net/xQnMd/1/.

    $("input").change(function() {
        var file = this.files[0];  // file
            fr   = new FileReader; // to read file contents
    
        fr.onloadend = function() {
            // get EXIF data
            var exif = EXIF.readFromBinaryFile(new BinaryFile(this.result));
    
            // alert a value
            alert(exif.Make);
        };
    
        fr.readAsBinaryString(file); // read the file
    });
    

提交回复
热议问题