Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Scriptmaster - use metadata extractor java library


This topic is 4322 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hi all

 

I have been looking at a java library for MetaData Extractor to grab the EXIF data from images

 

The library is here... http://drewnoakes.com/code/exif/

 

I added the 2 jar files from the download into Scriptmaster. I am not sure what to do next.

 

I created a new module and called it Get EXIF

 

I then added a new Input Variable of 'Image' (this is where a container field should be entered)

 

And an Output variable of 'EXIFdata'

 

The project Wiki says the code to read the metadata from an image is

 

File jpegFile = new File("myImage.jpg");
Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);

 

And the code to Output all Metadata Tag Values is 

 

for (Directory directory : metadata.getDirectories()) {
    for (Tag tag : directory.getTags()) {
        System.out.println(tag);
    }
}

 

 

Could anyone assist in putting this into some kind of format that I would need to enter into Scriptmaster to create the module please as I'm a little lost!

 

The 2 jar files (that I guess I need to load at the start?) are:

metadata-extractor-2.6.4.jar

xmpcore.jar

 

I hope I'm along the right lines and someone is able to help with the code I would need to enter into the Script of Scriptmaster!

 

Many thanks for any help you can give!

 

Posted

Hello,

 

… a way to get all the tags

// Function: metadaExtractor_getAllTags ( fileIn )
// Parameter(s)
//   fileIn : path to picture document

import com.drew.imaging.ImageMetadataReader
import com.drew.imaging.ImageProcessingException
import com.drew.metadata.Directory
import com.drew.metadata.Metadata
import com.drew.metadata.Tag

Metadata metadata = null
try {
    imgFile = new File(fileIn);
    metadata = ImageMetadataReader.readMetadata(imgFile);
} catch (ImageProcessingException ipx) {
    println ipx.message
}
if (metadata != null) {
    tagArray = []
    metadata.directories.each { Directory dir ->
        dir.tags.each { Tag tag ->
            tagArray << tag
        }
    }
    return tagArray
}
Posted

Hi,

 

Many thanks for your kind reply.

 

I tried the code but it returns 5 errors when running the script...

I couldn't copy and paste the error message so have attached as an image...

 

Also, looking at the code it looks like it is expecting a file path, is there anyway to get it to look at a container field instead please?

 

Many thanks once again

Posted (edited)

I tried the code but it returns 5 errors when running the script...

Did you load the metadata-extractor-2.6.4.jar file ?

 

 

to get all EXIF tags of an image contained in a container field use…

// Function: metadaExtractor_getAllTags ( fieldName )
// Parameter(s)
//   fieldName : a container filed name

import com.drew.imaging.ImageMetadataReader
import com.drew.imaging.ImageProcessingException
import com.drew.metadata.Directory
import com.drew.metadata.Metadata
import com.drew.metadata.Tag

Metadata metadata = null
try {
    bis = new BufferedInputStream(fmpro.getContainerStream( fieldName ))
    metadata = ImageMetadataReader.readMetadata(bis,true)
} catch (ImageProcessingException ipx) {
    println ipx.message
} catch (IOException ioe) {
    println ioe.message
}
if (metadata != null) {
    tagArray = []
    metadata.directories.each { Directory dir ->
        dir.tags.each { Tag tag ->
            tagArray << tag
        }
    }
    return tagArray
}

 

PS: if the pictures are not saved 'as reference' than load the file "xmpcore.jar" too.

Edited by clemhoff
Posted

I have this at the start

 

import com.xmpcore.*;
import com.metadata-extractor-2.6.4.*;

 

But the import of metadata-extractor throws up its own errors. Am I calling it incorrectly?

 

Thanks

Posted

Hi Clemhoff,

 

I tried your edit and I'm getting somewhere now  :laugh2:

 

Without calling anything, i.e. just purely using your code. I get an output now for a container field.

It is limited output though, not a lot of Exif data coming through.

 

From what I understand about Exif data, the data is stored in Directories of data. The current output looks like it is just loading 1 directory [Exif SubIFD]

 

I suspect it is something I am doing rather than your code. Is this because I am not calling in the jar files? What would be the correct format for doing this? The images will be stored in the database, not as a reference.

 

Thanks once again, your help is very much appreciated

Posted

theres a difference between loading the jars and using the classes in them

 

in the demo file ticking the tow jar files on teh jars tab will ensure they are loaded the first time the script is run (they then stay loaded till you exit FileMaker)

The imports at the top of the script then say you want to use those classes is the script

 

Can you post a demo file, or are you sure you know which meatadata stream you are looking for - it might be that there is none and therefore no amount of looking will help!

 

this simple function will tell you how many dictionaries are present in your image

 

import com.drew.imaging.ImageMetadataReader

jpegFile = new FileInputStream(fm_fileIn)
metadata = ImageMetadataReader.readMetadata(jpegFile)
return metadata.getDirectories()

then you can build a function which reads each one of these one at a time to see what is in it

 

replace 0 with number up to total numbe rof dictionaries... (starts with 0)


return metadata.getDirectories()[0].getTags()
Posted

Ahhhh! Sorry, very new to Scriptmaster and to Java for that matter. I thought the jars tab was just a reference of which jars the script used, I didn't realise there was functionality behind those checkboxes being ticked. That makes much more sense!  :yep:

 

I think in some cases all stream are being returned but in others this is not the case.

 

I have 5 images for example.

Within scriptmaster, with this new module, it is only returning data for [Exif SubIFD]

 

I have the Troi File Plugin which also can read Exif data. This is returning much more information including for example Exif Tag 271 (make of camera) this comes under Directory IFD0.

I also have a free plugin I found called ExifPlugin. This is OK but didn't quite get all the information I needed. But also with this plugin, these particular images are giving all of the streams as the Troi Plugin.

 

Just seems odd that this module is not returning the streams for these images.

 

Having said that, other images I try do return these tags with the scriptmaster module.

 

It's odd, it is certainly not the images not having the data there as the other 2 plugins are returning the data. But on the other hand it is not necessarily the module as it is too returning these tags, but not for these images.

Posted

That's extremely kind of you and makes much more sense now!

 

I have added a record and reattached the file here.

In this image you can see that the Directory of Exif IFD0 exists but no tags are returned from it.

 

This image 100% has tags under this Dir as if I run it under any other Exif reader program it returns the camera make/model etc. For example exporting the filed contents of my image and uploading it to http://exif-viewer.com/ shows the Make/Model/Software/Orientation etc

 

Do you have any idea why this would be? The library perhaps?

 

Many thanks once again for all your help!

 

Ed

 
Posted

From what I see using Phil Harvey's ExifTool against the image you provided in the FM file, is that the "User comment" tag contains data of type "base64Binary".
Apparently the "Metadata-Extractor"
API hangs on this data format (without throwing an error).

 

20130104_152439_rdf.xml

Posted

Many thanks again for helping.

 

Is it possible to either decode the base64 in that tag, skip/ignore the tag altogether or alternatively can I grab a specified set of tags instead of grabbing them all and risk it falling over on an issue like this?

 

Thanks

Posted

Hi Clemhoff

Am I able to just pull individual tags using these jars? If so how would I change the script for this?

Again, really appreciate the help

Thanks, Ed

This topic is 4322 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.