David Harris's Technology Blog

ColdFusion, Flex, and other stuff...   (and 341,536 hours, 23 mins in to my plan for global domination)

Search:

Calendar:

Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Subscribe:

Enter your email address to subscribe to this blog.

Archives By Subject:

Tags:

action script adobe air ajax cfug coldfusion flash flex frameworks free software fxug general jpgmetadatareader mac off topic opensource papervision spry

Recent Entries:

No recent entries.

Top Posts:

Recent Comments:

Top Commenters:

My Links:

RSS:


Introducing JpgMetadataReader.cfc V0.3

another update so soon you ask?

The main difference with this version is I removed the getter and setter functions for ITPC metadata and created the functions:

- getMetadataKeys( type ) - setMetadataKeys( type , keys )

Why did I do this?

Because every digital camera stores some type of it's own meta data. To get access to this you can call:

<cfset stMetaData   = oMetaData.getMetaDataStruct("C:\path\to\jpg\picture.jpg","FujiFilm Makernote")>
...no prizes for guessing the make of digital camera I have!...

So what you can do is set the default keys (to empty string) like this:

<cfset oMetaData.setMetadataKeys("FujiFilm Makernote","valueone,valuetwo,valuethree")>

That way you don't need to worry about lots of "structKeyExists" calls! :-)

Hope this makes sense, and any feed back will be welcomed!

Introducing JpgMetadataReader.cfc V0.2

Just when you think you are being clever, you find there is someone who has already been cleverer (is that a word?) than you!

I asked Mr Google about ColdFusion and EXIF and he told me about this: http://www.leavethatthingalone.com/blog/index.cfm/2006/5/16/Using-ColdFusion-to-Read-EXIF-Information-from-JPEGs

The same Java class was being used, but the really clever thing here is that you don't need to add that class to the lib dir/class paths in CF.

After reading this, and thinking how I plan to use my JpgMetadataReader.cfc, I have made to following changes:

- the init function now has the optional argument "JpegMetadataReader", which is "An instantiated object of com.drew.imaging.jpeg.JpegMetadataReader" (that's the hint) If you do not pass this in, it will attempt to create the java object, and if it is located in the lib/class path, you'll be fine :-)

- added the functions "getITPCKeys" and "setITPCKeys". These functions are used to define a comma delimited list of keys that MUST be returned in the result struct. The struct keys are inited with a value of "" (empty string) The default list is "Caption/Abstract,Keywords,Credit,Copyright Notice,Object Name" and is dirived from http://www.controlledvocabulary.com/imagedatabases/iptc_naa.html#IPTCchart

- added the optional argument "type" to "getMetaDataStruct". This will return only the type of meta data you specify. eg:

<cfset stMetaData   = oMetaData.getMetaDataStruct("c:\my\picture\here.jpg","exif")>
...will only return "exif" meta data. If this argument is not provided or is an empty string, any avalible meta data will be returned. If a non-existant type is provided, you will end up with a empty Struct.

So, enough info, now for some code:

<!---
...code here to create the java object...

eg:
MyJpegMetadataReaderJavaObject = loader.create("com.drew.imaging.jpeg.JpegMetadataReader");

...if you are using Mark Mandle's Java loader (http://javaloader.riaforge.org/)

--->


<cfset oMetaData   = createObject("component","org.harris.JpgMetadataReader").init(MyJpegMetadataReaderJavaObject)>

<cfset stMetaData   = oMetaData.getMetaDataStruct("c:\my\picture\here.jpg")>

<cfdump var="#stMetaData#">

The only difference here from the initial code snippet is that I have provided the Java class "com.drew.imaging.jpeg.JpegMetadataReader" in the variable "MyJpegMetadataReaderJavaObject"

What is really cool about the JavaLoader is that you can load ANY java class!

Enjoy!

Introducing JpgMetadataReader.cfc

Here is the JpgMetadataReader.cfc, why you would use it and how would use it.

Every JPG has meta data connected to it. The format I was mainly interested in was IPTC (International Press Telecommunications Council) standard. (more about that here The one I was most interested in was the "Caption", the idea being you could set this value up, upload the file and it would be available to be use on the sever when displaying it in an album view (in my case Simple Viewer) What is great about this is that you can assign the comment TO THE JPG, and thus storing the data in a single location, rather than the JPG in one place, and the information about it in another!

Along with the IPTC meta data there is also the EXIF (Exchangeable Image File Format) meta data. The EXIT meta data has lots of good stuff about when/how/what settings the camera used when the photo was taken. (More about that here)

There are 2 programs I use to set this meta data up, both are free (of course!)

- IrfanView (with all the plugins installed) http://www.irfanview.net/ - PixVue, which gives a nifty right click menu to add/edit the meta data. http://www.pixvue.com/

This CFC uses the Java class metadata-extractor-2.3.1.jar, which you can download from: http://drewnoakes.com/code/exif/releases/ You will need to put this in the ColdFusion "lib" directory and restart the ColdFusion instance.

Right, now for some code...

<cfset oMetaData   = createObject("component","JpgMetadataReader").init()>

<cfset stMetaData   = oMetaData.getMetaDataStruct("\path\to\my\picture.jpg")>

<cfdump var="#stMetaData#">

This will return ALL meta data to do with the JPG (EXIF, IPTC and any other) If it is not defined, it does not return it, so you would have to check for it before you attempt to output it...

I have only tested it on WindowsXP running CF7 on JPG files (as that's all I use...), but feel free to have a look at it use it!

If you find it really useful consider donating to http://drewnoakes.com/code/exif/releases/, as he did all the really hard work!

...in the mean time, this'll work fine until CF8 comes out with all this native built in!