Attached jpeg files aren't correctly displayed (orientation)
Using a samsung note 2. I can test this on some other devices if you'd like.
I'm not sure if it's a problem that would show up in the MMS or not, but this image isn't correctly displayed. The orientation in the jpeg isn't being used correctly to display the image. I can send you the source jpeg if you'd like.
The screenshot doesn't have the hue correctly, but that was just a problem with my screenshot application.

Also attached is what happens when I use the default messaging app.

Just my two cents as to what may be happening:
Many times with mobile cameras, regardless of orientation, the data is stored the same, how the camera senses it. Orientation is sensed, then an Exif tag is tacked on saying "this image should be rotated 90 degrees."
Applications not parsing the tag then never rotate it.
If I have time this weekend I might try and fix this. We <3 you Moxie!
I understand, thanks!
I've written this into other android apps, I think you want android.media.ExifInterface?
This URL talks about it some more:
http://stackoverflow.com/questions/3647993/android-bitmaps-loaded-from-gallery-are-rotated-in-imageview
The second answer discusses the situation where you don't have access to the file directly.
That looks like the right path.
Attached are a portrait image, and a landscape image, shot with my Galaxy S III. The geotagging is only so-so for precision so I didn't bother to remove it.
I tried both Jeffrey's Exif Tool and the "exif" utility available in Ubuntu, and they both show that the "Orientation" tag has this characteristic. May not be the best sample images as it seems either my camera firmware or particular CyanogenMod camera has left some corrupt-ish comments and poor Exif structure. But they show the difference.

As I said, I guess I'll give this a crack this weekend. Here we go!
All right. This is looking like a larger endeavor than it was initially.
ExifInterface, Android's class for parsing Exif data in images, only accepts file URI's as input.
So, with pure Android Java, the only way to detect an Exif orientation is to either a) use ExifInterface and have the image on disk (not okay for TextSecure) or b) query MediaStore (which is pointless anyways, because these images are not visible to the MediaStore, so it will always throw an exception).
That leaves two solutions: a) Bring in an external Exif library (like http://drewnoakes.com/code/exif/ - is the Apache License compatible with TextSecure's??) b) Hmmm... Write an Exif parser? I'd really rather not. or... c) Temporarily write images to disk for ExifInterface d) Hack around with ExifInterface's backend and monkey with the native calls...
@aaronsilber , I think it should be possible to express images as URIs. For the example above, the image in question is one that's attached during compose, which is always initially passed to TextSecure as a URI.
Images can definitely be expressed as URI's. And said URI can be passed to ExifInterface, and everything looks like it works. Then you realize that it's always returning a 0 for orientation... So, ExifInterface handles files correctly, but not content:// uri's.
stackoverflow: http://stackoverflow.com/questions/5574561/exif-data-tag-orientation-always-0
and another... http://stackoverflow.com/questions/8554264/how-to-use-exifinterface-with-a-stream-or-uri
They both outline either querying MediaStore, which is probably useless for this. I don't think it makes sense to pull in an entire library just to handle this tag. I will keep looking for a solution...
EDIT: with that said, metadata-extractor seems lightweight enough and well-maintained, and is also GPL compatible. https://code.google.com/p/metadata-extractor/
I wouldn't mind coding a "detect when you are accidentally MMSing a geotagged photo" feature if we pulled in a full Exif library! :)
As I mentioned further up in the thread, http://stackoverflow.com/questions/3647993/android-bitmaps-loaded-from-gallery-are-rotated-in-imageview (the third answer) talks about how to get the orientation without ExifInterface.
@arichnad I will give the MediaStore method (as the stackoverflow answer mentions) a shot. I believe it was giving me issues before but I'll definitely try it again.
Update:
MediaStore method isn't working. MediaStore isn't aware of the images, they aren't "indexed" and don't exist in the filesystem like normal JPG files would anyways.
ExifInterface definitely isn't going to work. I considered trying to hack around with the native library "exif_jni" as that is what ExifInterface uses behind-the-scenes, but decided it probably wasn't worth it.
So! I dug around AOSP and it looks like rather than devs actually fixing/improving ExifInterface and its years-old bugs, around the time of ICS, the stock Gallery app had its own simple Exif parser to deal with this precise issue. Pawing through the code, it's pretty simple, so I decided to give my two test images a look in GHex. Loop through bytes, and if you hit 0x0112, 8 bytes later you run into either 0x01, 0x03, 0x06, or 0x08 which correspond to 0, 180, 90, and 270 degrees respectively.
And in Jelly Bean? This has become a much more complex, full-featured, and modular Exif parser. Why, oh why, did they confine this to the Gallery app's implementation and not build off of ExifInterface then reference that!
Well, implemented concisely and with proper logic (ie: some images will either have no Exif, be improperly formatted, or maybe not even be an image) this could just be the simplest solution. The AOSP ICS Exif.java is actually a perfect example of how this could be done. Having seen the code, though, I'll likely just write my own simple, pared down parser.
http://androidxref.com/4.0.4/xref/packages/apps/Gallery2/src/com/android/gallery3d/data/Exif.java (ICS)

Thanks for doing that research. Even if their code isn't the absolute best, sometimes there is an advantage in using it directly, since they'll continue to maintain and update it, while we might not have the same amount of time to do so.
- moxie
On 09/03/2013 10:53 PM, aaronsilber wrote:
Update:
MediaStore method isn't working. MediaStore isn't aware of the images, they aren't "indexed" and don't exist in the filesystem like normal JPG files would anyways.
ExifInterface definitely isn't going to work. I considered trying to hack around with the native library "exif_jni" as that is what ExifInterface uses behind-the-scenes, but decided it probably wasn't worth it.
So! I dug around AOSP and it looks like rather than devs actually fixing/improving ExifInterface and its years-old bugs, around the time of ICS, the stock Gallery app had its own simple Exif parser to deal with this precise issue. Pawing through the code, it's pretty simple, so I decided to give my two test images a look in GHex. Loop through bytes, and if you hit 0x0112, 8 bytes later you run into either 0x01, 0x03, 0x06, or 0x08 which correspond to 0, 180, 90, and 270 degrees respectively.
And in Jelly Bean? This has become a much more complex, full-featured, and modular Exif parser. Why, oh why, did they confine this to the Gallery app's implementation and not build off of ExifInterface then reference that!
Well, implemented concisely and with proper logic (ie: some images will either have no Exif, be improperly formatted, or maybe not even be an image) this could just be the simplest solution. The AOSP ICS Exif.java is actually a perfect example of how this could be done. Having seen the code, though, I'll likely just write my own simple, pared down parser.
http://androidxref.com/4.0.4/xref/packages/apps/Gallery2/src/com/android/gallery3d/data/Exif.java (ICS)
— Reply to this email directly or view it on GitHub https://github.com/WhisperSystems/TextSecure/issues/331#issuecomment-23767526.
http://www.thoughtcrime.org
even an option to rotate the image before sending would help this. Plus once it rotates the image automatically it might be a useful feature to keep just in case the image is still turned or if the user wants to rotate an image sideways for the fun of it.
Hello! I apologize in advance if this is not the right place to ask. I see this defect was addressed 7 months ago and was wondering why it is still not fixed in the current version of TextSecure? I am a new user of TextSecure and would like to +1 this
I see this hasn't been fixed yet... +1
I added a PR for this: #1847
I had the same problem, maybe this solution will be useful for you.
Matrix matrix = new Matrix();
matrix.postRotate(getImageOrientation(data));
private int getImageOrientation(Intent data) {
Uri imageUri = data.getData();
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = getActivity().getContentResolver().query(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
Log.d("orientation", "Picture orientation: " + orientation);
} else {
Log.d("orientation", "Wrong picture orientation: " + orientation);
}
if (cur != null) cur.close();
return orientation;
}
Very confused that this issue is closed, and every related issue seemingly closed as a dupe of this issue or one that ultimately dupes to this issue, yet I still see an utter failure to have photos taken be properly rotated when I or anyone I converse with takes and sends photos via Signal.
@keithzg I think there are several open ones, like #8611 and #7671.
Possibly more here: https://github.com/signalapp/Signal-Android/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+orientation
Please find the suitable one and add any additional information you may have.