How to retrieve the exif orientation value in flutter

3,210

I used this function:

  needRotation(String path) async {
    Map<String, IfdTag> data =
        await readExifFromBytes(await new File(path).readAsBytes());
    return data['EXIF ExifImageWidth'].values[0] >
        data['EXIF ExifImageLength'].values[0];
  }

using import 'package:exif/exif.dart';

Explain: given the path of an image it will return if need rotation (i.e. is in landscape mode)

I also hadthe null orientation problem that u mentioned and uses the width/height to figure it out my self...

It seems weired I know... hope someone comes with a better solution.

Share:
3,210
dshukertjr
Author by

dshukertjr

LinkedIn: https://www.linkedin.com/in/dshukertjr/ Flutter, Next.js, Supabase and more!

Updated on December 13, 2022

Comments

  • dshukertjr
    dshukertjr over 1 year

    I am developing an app using Flutter and I want to retrieve the exif orientation value of an image that I selected using the image_picker plugin.

    When I run the code below and select an image that I have rotated beforehand, I get null for the orientation value and an empty Map for the exif data.

    File file = await ImagePicker.pickImage(
      source: ImageSource.gallery,
    );
    img.Image decodedImage = img.decodeImage(file.readAsBytesSync());
    print("decodedImage.exif.orientation ${decodedImage.exif.orientation}"); // null
    print("decodedImage.exif.data ${decodedImage.exif.data}"); // {}
    

    I send the image that I used with this code to my mac book through google drive to see the orientation value and this is what I got:

    enter image description here

    I am using the newest available version of the image_picker plugin. How can I retrieve the exif orientation value of an image in Flutter?