Metadata-extractor

hi

looking to read exif data & found:

which led to metadata-extractor.

https://drewnoakes.com/code/exif/

I appear to be able to import the jar after setting it up in the Processing library, but then it fails at basic commands

// lots of metadata-extractor import statements here…

File jpegFile;
Metadata metadata;

void setup() {
  size(960,640);
  
  jpegFile = new File("test_DSC2894.jpg");
  metadata = ImageMetadataReader.readMetadata(jpegFile);
}

‘Unhandled exception type ImageProcessingException’

any thoughts?

thanks

Mark

Hmm. Example on repo homepage is to load a path, not a File object-- although both may be valid.

Search the repo for ImageProcessingException. My guess is that you need to add a try / catch around your read to catch that exception, even if you do nothing but quit().

https://processing.org/reference/try.html

hi

thanks for trying …

but get same error from try / catch

File jpegFile;
Metadata metadata;

void setup() {
  size(960,640);
  jpegFile = new File("test_DSC2894.jpg");
  try {
    metadata = ImageMetadataReader.readMetadata(jpegFile);
  } catch (IOException e) {
    e.printStackTrace();
  }
}

No, don’t catch IOException. Catch ImageProcessingException. The one that the error is saying is unhandled. Handle that one. And / or check where the handing is failing, so that your wrapping location is correct.

thanks for reply

I’d tried that it gives error

‘Unhandled exception type IOException’

does this shed ant further light?

Every time you get an unhandled, you add a catch (except).

Unhandled Foo

try {
} except (Foo e) {
}

Unhandled Bar

try {
} except (Foo e) {
} except (Bar e) {
}

Unhandled Baz

try {
} except (Foo e) {
} except (Bar e) {
} except (Baz e) {
}

If an error asks you to handle an exception, handle the exception.

hi
got it working
needs path + two exceptions

below is proof of concept which dumps all exif etc to console

thanks for assist

Mark

// above this all metadata-extractor import stuff
File jpegFile;
Metadata metadata;

void setup() {
  size(960,640);
  jpegFile = new File("Documents/Proc3/exif_test2/test_DSC2894.jpg");
  try {
    metadata = ImageMetadataReader.readMetadata(jpegFile);
    println(metadata, "Using ImageMetadataReader");
    
    for (Directory directory : metadata.getDirectories()) {
      for (Tag tag : directory.getTags()) {
        System.out.println(tag);
      }
    }
  } catch (ImageProcessingException e) {
    println(e);
  } catch (IOException e) {
  print(e);
  }
}