Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable seems to not get set on mobile devices

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.

like image 214
FredTheDino Avatar asked Mar 22 '17 10:03

FredTheDino


1 Answers

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.

like image 158
SliceThePi Avatar answered Oct 24 '22 15:10

SliceThePi