Skip to content

Commit

Permalink
flutter#1 - Fixing GIF being exported as JPG issue
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondctc committed Mar 5, 2021
1 parent 105c2bc commit e1c51eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import android.content.Context;
import android.net.Uri;
import android.webkit.MimeTypeMap;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -39,7 +40,7 @@ String getPathFromUri(final Context context, final Uri uri) {
OutputStream outputStream = null;
boolean success = false;
try {
String extension = getImageExtension(uri);
String extension = getImageExtension(context, uri);
inputStream = context.getContentResolver().openInputStream(uri);
file = File.createTempFile("image_picker", extension, context.getCacheDir());
file.deleteOnExit();
Expand Down Expand Up @@ -67,13 +68,16 @@ String getPathFromUri(final Context context, final Uri uri) {
}

/** @return extension of image with dot, or default .jpg if it none. */
private static String getImageExtension(Uri uriImage) {
private static String getImageExtension(final Context context, Uri uriImage) {
String extension = null;

try {
String imagePath = uriImage.getPath();
final String imagePath = uriImage.getPath();
if (imagePath != null && imagePath.lastIndexOf(".") != -1) {
extension = imagePath.substring(imagePath.lastIndexOf(".") + 1);
} else if (imagePath != null && imagePath.lastIndexOf(".") == -1) {
final MimeTypeMap mime = MimeTypeMap.getSingleton();
extension = mime.getExtensionFromMimeType(context.getContentResolver().getType(uri));
}
} catch (Exception e) {
extension = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ public void onPathReady(String path) {

private void handleImageResult(String path, boolean shouldDeleteOriginalIfScaled) {
if (methodCall != null) {
if (path.toLowerCase().endsWith(".gif")) {
finishWithSuccess(path);
return;
}

Double maxWidth = methodCall.argument("maxWidth");
Double maxHeight = methodCall.argument("maxHeight");
Integer imageQuality = methodCall.argument("imageQuality");
Expand Down

0 comments on commit e1c51eb

Please sign in to comment.