# Metadata-extractor

**URL:** <https://discourse.processing.org/t/metadata-extractor/14798>\
**Category:** Libraries\
**Created:** [October 19, 2019, 12:37pm UTC](https://discourse.processing.org/t/metadata-extractor/14798 "2019-10-19T12:37:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![m47k0](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@m47k0](https://discourse.processing.org/u/m47k0)\
**Post date:** [October 19, 2019, 12:37pm UTC](https://discourse.processing.org/t/metadata-extractor/14798/1 "2019-10-19T12:37:35Z")

</div>

hi

looking to read exif data & found:

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/23425/get-metadata-from-pictures-e-g-exif)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

which led to metadata-extractor.

[https://drewnoakes.com/code/exif/](https://drewnoakes.com/code/exif/)

> **[drewnoakes/metadata-extractor](https://github.com/drewnoakes/metadata-extractor/wiki/Getting-Started-(Java))**
>
> Extracts Exif, IPTC, XMP, ICC and other metadata from image and video files - drewnoakes/metadata-extractor

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

```auto
// 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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 21, 2019, 3:11am UTC](https://discourse.processing.org/t/metadata-extractor/14798/2 "2019-10-21T03:11:17Z")

</div>

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](https://processing.org/reference/try.html)

---

<div class="post-metadata">

**Author:** ![m47k0](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@m47k0](https://discourse.processing.org/u/m47k0)\
**Post date:** [October 22, 2019, 6:32pm UTC](https://discourse.processing.org/t/metadata-extractor/14798/3 "2019-10-22T18:32:50Z")

</div>

hi

thanks for trying …

but get same error from try / catch

```auto
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();
  }
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 23, 2019, 2:27am UTC](https://discourse.processing.org/t/metadata-extractor/14798/4 "2019-10-23T02:27:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![m47k0](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@m47k0](https://discourse.processing.org/u/m47k0)\
**Post date:** [October 23, 2019, 7:57pm UTC](https://discourse.processing.org/t/metadata-extractor/14798/5 "2019-10-23T19:57:43Z")

</div>

thanks for reply

I’d tried that it gives error

‘Unhandled exception type IOException’

does this shed ant further light?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 24, 2019, 4:47pm UTC](https://discourse.processing.org/t/metadata-extractor/14798/6 "2019-10-24T16:47:56Z")

</div>

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

Unhandled Foo

```auto
try {
} except (Foo e) {
}

```

Unhandled Bar

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

```

Unhandled Baz

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

```

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

---

<div class="post-metadata">

**Author:** ![m47k0](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@m47k0](https://discourse.processing.org/u/m47k0)\
**Post date:** [October 24, 2019, 7:34pm UTC](https://discourse.processing.org/t/metadata-extractor/14798/7 "2019-10-24T19:34:28Z")

</div>

hi  
got it working  
needs path + two exceptions

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

thanks for assist

Mark

```auto
// 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);
  }
}

```
