flutter_native_image icon indicating copy to clipboard operation
flutter_native_image copied to clipboard

Preserve exif information after crompessed file

Open faspadaro opened this issue 7 years ago • 8 comments

I have a file taken from ImagePicker.pickImage that I want to resize and then I want to know his orientation because I want to it be always in portrait orientation for write image in pdf.

On Android I noticed after compressed file with flutter_native_image the exif information is lost. if you use brendan-duncan/image for decode image you'll notice that orientation is null.

File compressedFile = await FlutterNativeImage.compressImage(dat[i].path, quality: 80,
      targetWidth: 600,
      targetHeight: (properties.height * 600 / properties.width).round());
List<int> byte = compressedFile.readAsBytesSync();
Im.Image img = Im.decodeImage(byte);
int orientation = img.exif.orientation; # is null

faspadaro avatar Dec 12 '18 11:12 faspadaro

Hmm according to this part of my code, it should keep the exif information: https://github.com/btastic/flutter_native_image/blob/master/android/src/main/java/com/example/flutternativeimage/FlutterNativeImagePlugin.java#L83 Especially this part: https://github.com/btastic/flutter_native_image/blob/master/android/src/main/java/com/example/flutternativeimage/FlutterNativeImagePlugin.java#L197

If you can, I'd like to have a look at your picture to see what is happening in your case.

btastic avatar Dec 12 '18 17:12 btastic

This is screenshot

schermata 2018-12-12 alle 20 20 17

faspadaro avatar Dec 12 '18 19:12 faspadaro

Ok it looks like you are using brendan duncans library instead of mine. I am not sure about his implementation of his library, but I guess his library does not keep exif information. Maybe you could post a simplified version of your code so I could have a look at it.

btastic avatar Dec 12 '18 19:12 btastic

dependencies:
  image_picker: ^0.4.10
  cupertino_icons: ^0.1.2
  flutter_native_image:
    git: https://github.com/btastic/flutter_native_image.git
  image: ^2.0.4



class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      body:  Text(''),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          File fileFromPicker = await ImagePicker.pickImage(source: ImageSource.camera);
          ImageProperties properties = await FlutterNativeImage.getImageProperties(fileFromPicker.path);

          File compressedFile = await FlutterNativeImage.compressImage(fileFromPicker.path, quality: 100,
              targetWidth: 600,
              targetHeight: (properties.height * 600 / properties.width).round());
          List<int> byte = compressedFile.readAsBytesSync();

          Im.Image img = Im.decodeImage(byte);

          int orientation = img.exif.orientation;
          print('orientation ' + orientation.toString());
          // ...

        },
        tooltip: 'picker',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

faspadaro avatar Dec 13 '18 08:12 faspadaro

So I fiddled around with this for a bit and I found that there seems to be an issue. For the image resizing I am actually using googles code and I just checked on their repo, and they have the same issues right now aswell.

https://github.com/flutter/flutter/issues/12921

btastic avatar Dec 13 '18 13:12 btastic

It is now fixed!

They added an helper class that could be used in this plugin I guess.

aloisdeniel avatar Apr 29 '20 08:04 aloisdeniel

@btastic did you plan any update about this issue?

Sprechen avatar Jul 14 '21 09:07 Sprechen

Currently I am busy with other personal stuff and I don't have much time to have a deeper look at this. This is also something I can not easily implement without having an iOS device. Sorry for the inconveniences.

btastic avatar Jul 15 '21 22:07 btastic