Photo coming from the camera is rotated

Asked

Viewed 86 times

0

    <input 
        onChange={this.mostra} 
        type="file" 
        accept="image/jpeg" 
        name="img" 
        id="perfilfoto"/>

Function called when I choose a photo before sending;

    mostra = ()=> {
    
            var doc = document.querySelector("#perfilfoto");
    
            let fread = new FileReader();
            fread.readAsDataURL(doc.files[0]);
    
            fread.onloadend = event => {
                this.setState({url: ""});
                this.setState({fat: event.target.result});
            }
        }

When I look for the image of the gallery other than the camera, can be a print or download, it is in the normal position, however, if it is the camera or if it is taken at the time of sending, it is rotated... Thank you in advance

1 answer

1


EXIF 'Orientation Flag'

mostra = ()=> { 
let doc = document.querySelector("#perfilfoto")
let fread = new FileReader()

fread.onloadend = event => {
let photoExif = event.target.result

let dataURL =
`data:${ doc.files[0].type };base64,${ 
btoa( 
    photoExif.match(/Orientation>3/)? photoExif.replace(/Orientation>3/, 'Orientation>1')
  : photoExif.match(/Orientation>6/)? photoExif.replace(/Orientation>6/, 'Orientation>8')
  : photoExif
) }`;

this.setState({ url: '' })
this.setState({ fat: dataURL })
}

fread.readAsBinaryString( doc.files[0] )
}
inserir a descrição da imagem aqui

  • Still not rotating... What could be the problem? I can hardly find subjects for this theme... I do this in React and I test my phone by ip, is a Galaxy S7, if that can help

  • Wrong picture orientation on Samsung Devices : https://github.com/google/cameraview/issues/22 ; How to Automatically Rotate an image based on Exif data (on React): https://medium.com/@oscarfranco_14246/how-to-Automatically-Rotate-an-image-based-on-Exif-data-on-React-a41a27feb57c

Browser other questions tagged

You are not signed in. Login or sign up in order to post.