Uploading photo taken by mobile phone displays rotated image

2

I have a system with a Photo upload page. It is a simple photo upload, where you click on input , select the image and end. Then just send the form, the image is saved in a folder, and another html file happens to becuperation of the photo path, displaying the same inside a img tag.

If you use it on a phone or tablet, the operation is the same, the difference is that the option to take the picture with the camera appears, and then it retrieves the image exactly as it was taken and sent.

Everythingworksverywell,exceptthatithadauserofthesystem,thatwhentakingthephotos,thesystemrecoveredtheimagelyingdown,andthattookthephotoonfoot.Iwassavingtheimageonthepcfortesting,andtheimagecameintherightway.However,whenyouuploadit,itappearsagainlyingdown.Allthiswithoutmakinganychangestothefile.

Any image I take picture from my cell phone, or get on the internet is displayed correctly. Only pictures taken by that user's Tablet are displayed lying down. Even if I try to check the picture with Sublime Text, it displays the image lying down (rotated). I think it's something of the photo setup, which is set by Android. I researched, but I did not find anything specific.

What makes the photo appear like this?

    
asked by anonymous 30.09.2015 / 19:56

2 answers

2

If the photo was created with some kind of digital camera, it probably has goals that inform the camera's rotation at the time of click . You can use this feature to fix the rotation in your app.

ExifInterface stores this information on Android.

ExifInterface exif = new ExifInterface(uri.getPath());
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
// converte para graus
private static int exifToDegrees(int exifOrientation) {        
  if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; } 
  else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {  return 180; } 
  else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {  return 270; }            
return 0;     
} 
int rotationInDegrees = exifToDegrees(rotation);
ImageView imageId = (ImageView) findViewById(R.id.imageId) ;
picasso.load("URL").rotate(degrees).into(imageId) ;

Good luck.

    
02.10.2015 / 14:57
-2

If you wanted to check targets using PHP at the server level, you can use the exif_read_data function.

See in: link

There's even an example on the link talking about the orientation of the photo.

    
19.04.2018 / 22:09