Picasso: Rotate if necessary

Created on 7 Oct 2014  Â·  26Comments  Â·  Source: square/picasso

How can I rotate the picture automatically if the photo has been taken in a different orientation?

Most helpful comment

@JakeWharton Looks like they added one in support lib 25.1.0

Added ExifInterface support library. This library unbundles support for reading Exif information from JPEG and raw formatted files and setting the Exif information on JPEG image files.

All 26 comments

The File and MediaStore request handlers will parse EXIF data and rotate accordingly (file:// and content://) It looks like the NetworkRequestHandler doesn't support EXIF parsing at this time. Where are you retrieving the image from?

From the device storage, sd card or via other applications intents.

If you're using 2.3.4, you can see how EXIF orientation is handled here for files and here for media store requests. If you're looking at the latest code, check out FileRequestHandler and MediaStoreRequestHandler.

What I'm saying is - it should just work. If not, please feel free to get the source and debug.

What IDE should I use to recompile Picasso? I'm trying to do it on Android Studio, but I'm getting a lot of errors.

We use IntelliJ IDEA.
On Oct 7, 2014 4:06 AM, "Juliano Nunes" [email protected] wrote:

What IDE should I use to recompile Picasso? I'm trying to do it on Android
Studio, but I'm getting a lot of errors.

—
Reply to this email directly or view it on GitHub
https://github.com/square/picasso/issues/691#issuecomment-58168469.

Thank you. I'll try with it.

The image I have used has the ExifRotation = 90 and it is displayed incorrectly, however, if when debugging, I set the exifRotation to 0 (zero) and let the function matrix.preRotate(exifRotation); be called, the sizing works fine.

Here is the image I'm using.

20140928_214101

If the matrix.preRotate is called with exifRotation = 90 this picture is rotated but the sizing becomes wrong. Maybe the rotation should be applied before.

PS: I'm still debugging here...

What URI are you loading the image from?

The image is on my sdcard. I'm using the Gallery app to select the image.

Does that mean it's a content:// URI? If so, you should query the content provider and determine if the orientation column is set properly. The EXIF data on the file itself is not read, Picasso relies on the value from the mediastore content provider.

Yes. It's a content:// URI.

I can see the correct orientation value while debugging Picasso. I don't know where it comes from, but it does find the value

I've placed a breakpoint inside the BitmapHunter.hunt() function and here is a screenshot with the variables values.

picasso-sample

Ah, I see, this also sheds light on #689. The issue is not with rotation (it's displayed at the correct orientation - the photo should be portrait), but with the sizing of rotated images.

This also applies to requests with rotate(n) set, not just EXIF rotation.

To illustrate the issue - the first an image with no EXIF rotation, the second image is the same image with rotate(-90) applied. Both requests have .fit() and .centerCrop().

screen shot 2014-10-11 at 11 32 27 am
screen shot 2014-10-11 at 11 32 57 am

@julianonunes see #699 for a workaround if you're willing to build from source.

Thank you Jacob. I'll try it.

BTW, great photo. :-)

UPDATE

I just tested and it's working. Thank you again.

Not sure why Picasso still can't respect exif rotation when Glide can.

Because we don't implement JPEG parsing.

@JakeWharton so this happens on jpg images only?

Are there any plans to support parsing the exif tags for orientation?

Not unless Android adds an API for it.

On Tue, Dec 6, 2016, 8:16 PM Tyler Pfaff notifications@github.com wrote:

Are there any plans to support parsing the exif tags for orientation?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/square/picasso/issues/691#issuecomment-265326084, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEERRt1-csYFUEJn3NVC-zpQ_zIcTiks5rFgjggaJpZM4Crgta
.

@tpfaff checkout Glide, it's used at Target and Google (e.g. Google Photos)

You can leave Target off that list.

On Wed, Dec 7, 2016 at 10:04 AM Aidan Follestad notifications@github.com
wrote:

@tpfaff https://github.com/tpfaff checkout Glide
https://github.com/bumptech/glide, it's used at Target and Google (e.g.
Google Photos)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/square/picasso/issues/691#issuecomment-265470215, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEET4RpqeDovdT6LKIHxm6loaBja7fks5rFsrpgaJpZM4Crgta
.

@JakeWharton Looks like they added one in support lib 25.1.0

Added ExifInterface support library. This library unbundles support for reading Exif information from JPEG and raw formatted files and setting the Exif information on JPEG image files.

Was this page helpful?
0 / 5 - 0 ratings