How to work with iOS upside down

I use the input box on the website so that the user can take himself in the photo.

On iPad, iPhone, the resulting image is upside down. How can I easily determine if the user has used the camera so that I rotate the image using Javascript?

I use the image in Javascript canvas after.

I got this input field:

<div class="input-field">
    <label>Choose image or take a picture :</label>
    >input type="file" id="imageLoader" name="imageLoader" accept="image/*"/>
</div>

And in JS:

var imageLoader;
imageLoader = document.getElementById('imageLoader');
imageLoader.addEventListener('change', _handleImage, false);

function _handleImage( e ){

    var reader = new FileReader();

    reader.onload = function(event){

        picture.onload = function(){
           // The image here is upside down :( I want to turn it to 180 degrees here
           do_stuff( );

        };

        picture.src = event.target.result;

    };
    reader.readAsDataURL(e.target.files[0]);
}
+4
source share
2 answers

I managed to do this with these libs (I have no links in my mind except Google, these specific versions work):

  • Javascript EXIF ​​Reader 0.1.4
  • Binary Ajax 0.1.10

Gets the full code:

HTML:

<div class="input-field">
    <label>Choose image or take a picture :</label>
     <input type="file" id="imageLoader" name="imageLoader" accept="image/*"/>
</div>

JS:

var imageLoader, _isUpsideDown = false;
imageLoader = document.getElementById('imageLoader');
imageLoader.addEventListener('change', _handleImage, false);

function _handleImage( e ){

    var reader = new FileReader();

    reader.onload = function(event){

        picture.onload = function(){
            // Launch Canvas, display image, etc...
            doStuff();

        };

        picture.src = event.target.result;

    };
    reader.readAsDataURL(e.target.files[0]);

    // Second file reader which will read the file as binaryString to detect the orientation.
    var file = this.files[0];  // file
    filereaderString   = new FileReader; // to read file contents

    filereaderString.onloadend = function() {

        // get EXIF data
        var exif = EXIF.readFromBinaryFile(new BinaryFile(this.result));

        // the 3 value means that the image is upside down. 1 is when the image is correct size.
        if( exif.Orientation === 3 ){
            _isUpsideDown = true;
        }

    };

    filereaderString.readAsBinaryString(file); // read the file
}
+2
source

? ? , . .

, , :

var angle = 0;
$('#portraitButton').on('click', function() {
    angle = 90;
    $("#picture").rotate(angle);
});

$('#landscapeLeft').on('click', function() {
    angle = 180;
    $("#picture").rotate(angle);
});

$('#landscapeRight').on('click', function() {
    angle = 180;
    $("#picture").rotate(angle);
});

$('#upsideDown').on('click', function() {
    angle = -90;
    $("#picture").rotate(angle);
});

: http://jsfiddle.net/s6zSn/382/

, :)

+2

Source: https://habr.com/ru/post/1547899/


All Articles