Fix large images sometimes not respecting EXIF orientation.

Fixes #11614
This commit is contained in:
Art Chaidarun
2022-01-01 22:12:27 -05:00
committed by Greyson Parrelli
parent ac90eeb42f
commit 49a1a4a123
3 changed files with 31 additions and 9 deletions

View File

@@ -244,16 +244,19 @@ public class BitmapUtil {
return options;
}
public static int getExifOrientation(ExifInterface exif) {
return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
}
@Nullable
public static Pair<Integer, Integer> getExifDimensions(InputStream inputStream) throws IOException {
ExifInterface exif = new ExifInterface(inputStream);
int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
public static Pair<Integer, Integer> getExifDimensions(ExifInterface exif) {
int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
if (width == 0 || height == 0) {
return null;
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
int orientation = getExifOrientation(exif);
if (orientation == ExifInterface.ORIENTATION_ROTATE_90 ||
orientation == ExifInterface.ORIENTATION_ROTATE_270 ||
orientation == ExifInterface.ORIENTATION_TRANSVERSE ||

View File

@@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.WorkerThread;
import androidx.exifinterface.media.ExifInterface;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.gif.GifDrawable;
@@ -189,7 +190,7 @@ public class MediaUtil {
try {
if (MediaUtil.isJpegType(contentType)) {
attachmentStream = PartAuthority.getAttachmentStream(context, uri);
dimens = BitmapUtil.getExifDimensions(attachmentStream);
dimens = BitmapUtil.getExifDimensions(new ExifInterface(attachmentStream));
attachmentStream.close();
attachmentStream = null;
}