I'm reading an image file and rescaling it to send it to a server. In order to properly rescale it I need to change the orientation, since some pictures are taken with a mobile device camera. In order to do this rotation I did the following using the exif.js library:
EXIF.getData(img, function() {
alert(this.exifdata.Orientation);
orientation = this.exifdata.Orientation;
alert(orientation);
}
If this.exif.data.Orientation
was, for example 6, the following output would be desierd: "6", "6".
This works when a file is uploaded via my computer. However, when uploaded from a mobile device camera, the output is "6" and then "0", no matter what value orientation
had before.
Why does this happen?
Note: I'm only running on one thread. So the variable could not have been set externally during execution of these lines.
The global variable window.orientation
represents the orientation of the screen on mobile devices, and it's immutable. Changing the name of the variable- or putting var
, let
, or const
before it to declare it locally- will fix your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With