Code Monkey home page Code Monkey logo

dartexif's Introduction

exif

Pub Package Dart CI

Dart package to decode Exif data from TIFF, JPEG, HEIC, PNG and WebP files.

Dart port of ianaré sévi's EXIF library: https://github.com/ianare/exif-py.

Usage

  • Simple example:
printExifOf(String path) async {

  final fileBytes = File(path).readAsBytesSync();
  final data = await readExifFromBytes(fileBytes);

  if (data.isEmpty) {
    print("No EXIF information found");
    return;
  }

  if (data.containsKey('JPEGThumbnail')) {
    print('File has JPEG thumbnail');
    data.remove('JPEGThumbnail');
  }
  if (data.containsKey('TIFFThumbnail')) {
    print('File has TIFF thumbnail');
    data.remove('TIFFThumbnail');
  }

  for (final entry in data.entries) {
    print("${entry.key}: ${entry.value}");
  }

}

dartexif's People

Contributors

alexays avatar bhavin-concetto avatar bigflood avatar cachapa avatar gmpassos avatar gwanhyeong avatar jackdreilly avatar kennylevinsen avatar sese-schneider avatar ua741 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dartexif's Issues

Range Error using ReadExifFromBytes

Range Error is reported when ReadExifFromBytes read an image file with Exif data having fieldOffset larger than file size or byte array size. The error comes from setPositioinSync in file_interface.dart. There is no bound checking in the function. This does not cause problem using ReadExifFromFile. It may be because file.setPositionSync(position) is more robust in file_interface_io.dart's setPositionSync.

License

I was wondering why the library is GPL and not something more compatible with commercial apps like Apache-2

Convert GPS data into lat long coordinates

Hey,
I'm trying to get from images the latitude and longitude coordinates from images.

I succeed to implement something, but apperntly it's not working all the time:

 Map<String, double> _convertToLatLng(List lat, String latRef, List long, String longRef) {
    try {
      if (lat == null || latRef == null || long == null || longRef == null) return {};

      double latitude;
      double longitude;

      if (latRef == 'N') 
        latitude = _convertToDegree(int.tryParse(lat[0].toString()), int.tryParse(lat[1].toString()), lat[2].toString());
      else 
        latitude = 0 - _convertToDegree(int.tryParse(lat[0].toString()), int.tryParse(lat[1].toString()), lat[2].toString());

      if (longRef == 'E') 
        longitude = _convertToDegree(int.tryParse(long[0].toString()), int.tryParse(long[1].toString()), long[2].toString());
      else 
        longitude = 0 - _convertToDegree(int.tryParse(long[0].toString()), int.tryParse(long[1].toString()), long[2].toString());

      return { 'latitude': latitude, 'longitude': longitude };
    } catch(ex) {
      print('_convertToLatLng ex: $ex');
      return {};
    }
  }

  double _convertToDegree(int deg, int min, String secondsFormula) {
    final List<String> strSeconds = secondsFormula.split('/');
    final double seconds = int.tryParse(strSeconds[0]) / int.tryParse(strSeconds[1]);

    return deg + (min / 60) + (seconds / 3600);
  }

Do I miss something ?

Dead package ?

Judging by the issues and the latest answers in 2021, I have a question: does anyone continue to work on this project or not?

Image Orientation orientation always zero

Image Orientation {Image ImageWidth: 3264, Image ImageLength: 2448, Image ExifOffset: 62, Image Orientation: 0, EXIF LightSource: Unknown} - picture rotated 90 degrees

IPTC

Hey there, thanks a lot for this package!! I was wondering if it could be possible to implement the extraction of IPTC data as well.. i was trying to add hex-values to you list of tags, but it didnt work out (by now).

`0x0207: 'Edit Status',
// CONTENT #############################
0x0269: 'Headline',
0x0278: 'Description',
0x027a: 'Description Writer/Editor',
0x020f: 'Category',
0x0214: 'Other Categories',

// CONTACT #############################
0x0250: 'Creator',
0x0255: 'Job-Title',
0x025a: 'City',
0x025f: 'Province/State',
0x0264: 'PLZ',
0x0265: 'Country/Primary Location Name',

// IMAGE ########################################
0x0237: 'Date Created',
0x023c: 'Time Created',

/* 0x025a: 'City',
0x025f: 'State',
0x0265: 'Country/Primary Location Name',
0x0264: 'Country/Primary Location Code',*/

// STATUS ###########################
0x020a: 'Urgency',
0x0228: 'Special Instructions',
0x022a: 'Action Advised',

// COPYRIGHT ############################
0x0274: 'Copyright Notice',

// Contact Info
0x0276: 'Contact',

// Media
0x0114: 'File Format',
0x0116: 'File Format Version',
0x0282: 'Image Type',
0x0283: 'Image Orientation',

// Image Preferences
0x024b: 'Object Cycle',

// Event and Location

/* 0x025a: 'City',
0x025f: 'Province/State',
0x0264: 'Country/Primary Location Code',
0x0265: 'Country/Primary Location Name',*/

// Locations Taken and Shown
0x021a: 'Content Location Code',
0x021b: 'Content Location Name',

// Licensing
0x02ba: 'Short Document ID',
0x02bb: 'Unique Document ID',
0x02bc: 'Owner ID',`

readExifFromBytes & readExifFromFile are marked as Async but are technically Sync function

Future<Map<String, IfdTag>> readExifFromBytes(List<int> bytes,
    {String? stopTag,
    bool details = true,
    bool strict = false,
    bool debug = false,
    bool truncateTags = true}) async {
  return readExifFromFileReader(FileReader.fromBytes(bytes),
          stopTag: stopTag,
          details: details,
          strict: strict,
          debug: debug,
          truncateTags: truncateTags)
      .tags;
}

Since readExifFromFileReader is a sync function readExifFromBytes should be too.
It's currently make us believe that there is some async process running

readExifFromBytes throwing an error, for iOS 16

"type 'FieldType' is not a subtype of type 'int'"
#0 new PrintFormat. (package:sprintf/src/sprintf_impl.dart:14:41)
#1 PrintFormat.call (package:sprintf/src/sprintf_impl.dart:88:39)
#2 ExifHeader.processTag (package:exif/src/exifheader.dart:120:38)
#3 ExifHeader.dumpIfd (package:exif/src/exifheader.dart:91:9)
#4 DecodeMakerNote._dumpIfd2 (package:exif/src/exif_decode_makernote.dart:294:16)
#5 DecodeMakerNote._decodeApple (package:exif/src/exif_decode_makernote.dart:166:5)
#6 DecodeMakerNote._decodeMakerNote (package:exif/src/exif_decode_makernote.dart:76:9)
#7 DecodeMakerNote.decode (package:exif/src/exif_decode_makernote.dart:38:5)
#8 readExifFromFileReader (package:exif/src/read_exif.dart:104:54)
#9 readExifFromBytes (package:exif/src/read_exif.dart:26:10)

package:sprintf/src/sprintf_impl.dart

Jpg issue

I receive a No exif information exception for this picture:
https://user-images.githubusercontent.com/16626063/117620390-c08f4380-b170-11eb-8630-ff300692695a.jpg

with this tool (http://exif.regex.info/exif.cgi), data are read correctly.

Do you think you can investigate ?
I tried but i'm a bit lost in the middle of the code/specs

Thanks

JFIF

JFIF Version	1.01
Resolution	300 pixels/inch
File — basic information derived from the file.

File Type	JPEG
File Type Extension	jpg
MIME Type	image/jpeg
Encoding Process	Progressive DCT, Huffman coding
Bits Per Sample	8
Color Components	3
File Size	72 kB
Image Size	853 × 480
Y Cb Cr Sub Sampling	YCbCr4:2:0 (2 2)
Composite
This block of data is computed based upon other items. Some of it may be wildly incorrect, especially if the image has been resized.

Megapixels	0.409

Not all tags is fetching from exif

exif version 1.0
Have a look this image
If you use tool like http://exif.regex.info/exif.cgi you can see data like camera, location and son on.

But when I try to use exactly the same image with this library it shows only:

Image Orientation (Short): Horizontal (normal)
Image ExifOffset (Long): 38
ColorSpace (Short): sRGB
ExifImageWidth (Long): 640
ExifImageLength (Long): 480

Where is the rest tags? Why it doesn't parse properly all tags?

the code I use:

file.then((fileData) async {
              Map<String, IfdTag> data  = await readExifFromBytes(fileData);
              if (data == null || data.isEmpty) {
                debugPrint("No EXIF information found\n");
              return;
              }
          
              for (String key in data.keys) {
                debugPrint("$key (${data[key].tagType}): ${data[key]}");
              }
            });

PS. Sorry after more test I figure out that issue with image picker library and iOS. On Android everything works fine

Cause RangeError for some images

Hi, Thank you for making the package.
I noticed that readExifFromBytes causes RangeError for some images.
I am not sure which image cause that. But the image which caused the error was the image cropped by the smart phone application.

E/flutter (23641): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (23641): RangeError (start): Invalid value: Only valid value is 0: 8
E/flutter (23641): #0 RangeError.checkValidRange (dart:core/errors.dart:327:7)
E/flutter (23641): #1 List.sublist (dart:core/runtime/libgrowable_array.dart:81:22)
E/flutter (23641): #2 make_string_uc (package:exif/src/util.dart:31:13)
E/flutter (23641): #3 ExifHeader.dump_ifd (package:exif/src/exifheader.dart:350:35)
E/flutter (23641): #4 readExifFromFileReader (package:exif/src/read_exif.dart:241:9)
E/flutter (23641): #5 readExifFromBytes (package:exif/src/read_exif.dart:22:17)

Helper to strip exif data

I'm interested in this lib in order to strip out exif data from jpegs, but I don't see a top-level helper to do that. Would you be interested in adding that to the API?

My particular use case is allowing users to insert images into our app, but without the exif data.

I know some exif data (e.g. rotation) affect appearance, so perhaps this API should/could be more intelligent than just stripping and instead apply relevant transforms?

Anyway, just wanted to get a feel for the idea. Happy to implement if it's desired, though probably not for a few months due to work priorities.
Thanks!

EXIF orientation is incorrect

Hi, I am using Flutter with the camera plugin.
It seems that the library always reports orientation 6 which means landscape left which is incorrect.

I use the following code to determine the orientation from EXIF:

Future<int> getEXIFOrientationCorrection(List<int> image) async {

  int rotationCorrection = 0;
  Map<String, IfdTag> exif = await readExifFromBytes(image);

  if (exif == null || exif.isEmpty) {
    print("No EXIF information found");
  } else {
    print("Found EXIF information");
    // http://sylvana.net/jpegcrop/exif_orientation.html
    IfdTag orientation = exif["Image Orientation"];
    int orientationValue = orientation.values[0];
    // in degress
    print("orientation: ${orientation.printable}/${orientation.values[0]}");
    switch (orientationValue) {
      case 6:
        rotationCorrection = 90;
        break;
      case 3:
        rotationCorrection = 180;
        break;
      case 8:
        rotationCorrection = 270;
        break;
    }
  }
  return rotationCorrection;
}

orientation.values[0] seems to always be 6.
Tested with Iphone 7 (should have orientation=1) and Samsung Galaxy S3 mini (should have orientation=6).

However, for both phones the library reports orientation=6 which is wrong for the iPhone.
If I analyze the image with imagemagick, it reports orientation=1 which is correct for the iPhone 7:

$ identify -format '%[EXIF:Orientation]' flutter_camera_portrait.jpg
1

I took the image with the camera plugin on Iphone 7 and retrieved it from the device by printing it's base64 value to stdout. See the image here:
flutter_camera_portrait

Upgrade to sprintf 7.0.0

Because xyz_app depends on exif 3.1.2 which depends on sprintf ^6.0.0, sprintf ^6.0.0 is required.

sprintf is already at a major version bump (7.0.0), would be nice to get this plugin also synced with that.

How can I convert lat log data to real world data?

I checked with my image which have lat lng information

code is as exampled.


final data = await readExifFromBytes(fileBytes);

  if (data.isEmpty) {
    print("No EXIF information found");
    return;
  }

  for (final entry in data.entries) {
    print("${entry.key}: ${entry.value}");
  }

but result is

I/flutter (29756): GPS GPSDate: 2021:12:18
I/flutter (29756): GPS GPSProcessingMethod: [65, 83, 67, 73, 73, 0, 0, 0, 71, 80, 83, 0]
I/flutter (29756): GPS GPSTimeStamp: [14, 48, 34]
I/flutter (29756): GPS GPSAltitude: 13483/125
I/flutter (29756): GPS GPSAltitudeRef: 0
I/flutter (29756): GPS GPSLongitude: [127, 5, 150143/10000]
I/flutter (29756): GPS GPSLongitudeRef: E
I/flutter (29756): GPS GPSLatitude: [35, 48, 40797/1250]
I/flutter (29756): GPS GPSLatitudeRef: N
I/flutter (29756): Image ExifOffset: 212

how can I convert GPS latitude like 35, 48, 40797/1250 to gps data to search in google map?

Exif data, why can the map key be null?

Future<Map<String?, IfdTag>?> readExifFromBytes

I'm not sure why you would expect an IfdTag with a null key?

Future<Map<String, IfdTag>?> readExifFromBytes is what I would assume to be correct?

exif datas not found with CR3 pictures

Hi,
I am trying to extract exif data to get the DateTimeOriginal information.
The script work very well with JPEG and Nikon NEF files.
But with Canon CR3 files, i get an empty list from the readExifFromBytes function.

Here is the script i use:

import 'dart:io';
import 'package:exif/exif.dart';
import 'package:exif_test/exif_test.dart' as exif_test;

void main(List<String> arguments) async {
  // String filename = './DSC_0700_038.JPG';
  // String filename = './DSC_1270.NEF';
  String filename = './OD2_2676.CR3';

  print("read $filename ...");

  final fileBytes = File(filename).readAsBytesSync();
  final data = await readExifFromBytes(
    fileBytes,
    // debug: true,
  );

  if (data.isEmpty) {
    print("No EXIF information found");
    return;
  }

  if (data.containsKey('JPEGThumbnail')) {
    print('File has JPEG thumbnail');
    data.remove('JPEGThumbnail');
  }
  if (data.containsKey('TIFFThumbnail')) {
    print('File has TIFF thumbnail');
    data.remove('TIFFThumbnail');
  }

  for (final entry in data.entries) {
    print("${entry.key}: ${entry.value}");
  }
}

Do I miss something? Or is there a restriction for extracting EXIF data from Canon CR3 files?

Il also try with a node.js script i wrote with the npmjs exiftools-vendored package and i can réead exif datas from CR3 file with this javascript package. So i am shure that EXC-IF datas are present in this CR3 file.

Unable to identify EXIF tags in attached image

https://albums.ente.io?t=C5afhVdr#9spNGaMztMxKjL8Nu4z2t8dCRub2BAqJUgUfqUoRdCJi
https://i.redd.it/zm4nfgq29yi91.jpg

The dartexif package returns 0 exif tags while the exiftool is able to identify the correct exif data.

ExifTool Version Number         : 12.42
File Name                       : sample_image.jpg
Directory                       : .
File Size                       : 13 MB
File Modification Date/Time     : 2022:08:22 14:21:54+05:30
File Access Date/Time           : 2022:08:22 14:26:36+05:30
File Inode Change Date/Time     : 2022:08:22 14:22:33+05:30
File Permissions                : -rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Profile CMM Type                : Linotronic
Profile Version                 : 2.1.0
Profile Class                   : Display Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 1998:02:09 06:49:00
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : Hewlett-Packard
Device Model                    : sRGB
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Media-Relative Colorimetric
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Hewlett-Packard
Profile ID                      : 0
Profile Copyright               : Copyright (c) 1998 Hewlett-Packard Company
Profile Description             : sRGB IEC61966-2.1
Media White Point               : 0.95045 1 1.08905
Media Black Point               : 0 0 0
Red Matrix Column               : 0.43607 0.22249 0.01392
Green Matrix Column             : 0.38515 0.71687 0.09708
Blue Matrix Column              : 0.14307 0.06061 0.7141
Device Mfg Desc                 : IEC http://www.iec.ch
Device Model Desc               : IEC 61966-2.1 Default RGB colour space - sRGB
Viewing Cond Desc               : Reference Viewing Condition in IEC61966-2.1
Viewing Cond Illuminant         : 19.6445 20.3718 16.8089
Viewing Cond Surround           : 3.92889 4.07439 3.36179
Viewing Cond Illuminant Type    : D50
Luminance                       : 76.03647 80 87.12462
Measurement Observer            : CIE 1931
Measurement Backing             : 0 0 0
Measurement Geometry            : Unknown
Measurement Flare               : 0.999%
Measurement Illuminant          : D65
Technology                      : Cathode Ray Tube Display
Red Tone Reproduction Curve     : (Binary data 2060 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 2060 bytes, use -b option to extract)
Blue Tone Reproduction Curve    : (Binary data 2060 bytes, use -b option to extract)
Image Width                     : 13216
Image Height                    : 13216
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 13216x13216
Megapixels                      : 174.7

Publish package

The current GitHub master version of exif, 1.0.3, is not published yet at pub.dev.

Please, publish it, since is a importante feature, be portable and be able use it in a Web context too.

Best regards.

dartexif reports 0/0, 0/0, 0/0 for lat/lon, but file is geotagged

exif.tools web site reports the correct lat/lon, but all I see in the data from dartexif is this:

I/flutter (25377): GPS GPSVersionID: [0, 0, 0, 0] I/flutter (25377): GPS GPSLatitudeRef: I/flutter (25377): GPS GPSLatitude: [0/0, 0/0, 0/0] I/flutter (25377): GPS GPSLongitudeRef: I/flutter (25377): GPS GPSLongitude: [0/0, 0/0, 0/0] I/flutter (25377): Image GPSInfo: 1012
I thought maybe the file had GPS info stripped out, so i transferred it from the android emulator to my windows desktop, then uploaded to exif.tools web site, and it reports the correct lat/lon.

Is there something wrong in my process?

add null-safety support

since flutter stable 2.0.0 is there with stable null safety, it would be nice to have this package migrated as well

Bad state: No element while reading Exif

Exception stack trace

StateError: Bad state: No element
  File "list.dart", line 222, in ListMixin.reduce
  File "util.dart", line 37, in makeString
  File "values_to_printable.dart", line 24, in new ValuesToPrintable.convert
  File "exifheader.dart", line 128, in ExifHeader.processTag
  File "exifheader.dart", line 91, in ExifHeader.dumpIfd
  File "exif_decode_makernote.dart", line 280, in DecodeMakerNote._dumpIfd
  File "exif_decode_makernote.dart", line 107, in DecodeMakerNote._decodeNikon
  File "exif_decode_makernote.dart", line 60, in DecodeMakerNote._decodeMakerNote
  File "exif_decode_makernote.dart", line 38, in DecodeMakerNote.decode
  File "read_exif.dart", line 104, in readExifFromFileReader
  File "read_exif.dart", line 44, in readExifFromFile

not getting latitude and longitude from image

Can not able to get LatLng co-ordinate from image using exif.

image

Getting 58 map items but can't able to find LatLng co-ordinates also tried with GPS as well.
final latRef = data['GPS GPSLatitudeRef']?.toString();
print("ref"+latRef.toString());
var latVal = gpsValuesToFloat(data['GPS GPSLatitude']?.values);

Bu it is giving null values from exif

Cannot read EXIF from jpeg image from phone gallery

I have tried loading a gallery image and passed to the function

try {
      Map<String, IfdTag> data = await readExifFromBytes(
          await file.readAsBytes()); // no future, only assigns after getting?

      if (data == null || data.isEmpty) {
        print("No EXIF information found\n");
        return;
      }
...

The code is caught with the exception

failed to read exif data!
I/flutter ( 8948): whereType is not yet supported

Now is that my image issue or I am calling the function wrong entirely?

there is no any gps information

I try to get the GPS information from the image but it seems can't find anythings, what's the key should I take for get the lat/lng info?

thanks!

Can not get orientation exif infomation of image captured with camera plugin

When I use your example in https://github.com/bigflood/exifviewer, I cannot get orientation info of the captured image with camera plugin, but the picked image have this info. This is a bug in your library or camera plugin do not write orientation info to the captured image?

Screenshot_20190620-110930
Screenshot_20190620-110953

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.7.5-pre.21, on Microsoft Windows [Version 10.0.17763.557], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
[√] Android Studio (version 3.4)
[√] VS Code (version 1.33.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.