FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   pulling exif / iptc data from jpegs (???)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: pulling exif / iptc data from jpegs (???)  (Read 480 times)
mKoser

WWW Email
pulling exif / iptc data from jpegs (???)
« on: Feb 18th, 2004, 2:02pm »

exit and iptc metatags are the tags cameras, scanners and software like photoshop uses to save information within an image.
 
i just started playing with an external library i found:  
http://www.drewnoakes.com/code/exif/index.html
 
first of i (to try and make it work) i followed the example code given on the website: http://www.drewnoakes.com/code/exif/sampleUsage.html
 
...hmmm, but an error is being thrown:
Code:
The method "com.drew.metadata.Metadata readMetadata(java.io.File $1) throws com.drew.imaging.jpeg.JpegProcessingException

 
i have placed the .jar file in the /code/ lib as it is supposed to be, and the JPG-image I am trying to import is in the /data/ folder (i've also tried putting it in the sketch's root folder and the /data/ folder)
 
Code:

File jpegFile;
Metadata metadata;
 
void setup(){
  size(640, 480);
}
 
void draw(){
  jpegFile = new File("P2140002.JPG");
  metadata = JpegMetadataReader.readMetadata(jpegFile);
  displayData();
}
 
void displayData(){
  // iterate through metadata directories
  Iterator directories = metadata.getDirectoryIterator();
  while (directories.hasNext()) {
    Directory directory = (Directory)directories.next();
    // iterate through tags and print to System.out
    Iterator tags = directory.getTagIterator();
    while (tags.hasNext()) {
 Tag tag = (Tag)tags.next();
 // use Tag.toString()
 System.out.println(tag);
    }
  }
}

 
Does anyone have a good idea as to how i can get this working?
 
Thanks
Mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
arielm

WWW
Re: pulling exif / iptc data from jpegs (???)
« Reply #1 on: Feb 18th, 2004, 2:21pm »

not tested, but it could be as simple as enclosing the "guilty" method call into a try-catch block, e.g.:
 
Code:

try
{
  metadata = JpegMetadataReader.readMetadata(jpegFile);
}
catch (JpegProcessingException e)
{
  println("an error occured while...");
  // do something to gracefully handle your program flow here...
}

note that if the "JpegProcessingException" is not recognized by the compiler, using "Exception" instead should work too...
 
warning when using try-catch blocks: new variables should not be declared "inside" (declaring is different than assigning a value), otherwise they won't be recognized "outside".
 
hth, and welcome to the "pure java" club
« Last Edit: Feb 18th, 2004, 2:25pm by arielm »  

Ariel Malka | www.chronotext.org
mKoser

WWW Email
Re: pulling exif / iptc data from jpegs (???)
« Reply #2 on: Feb 18th, 2004, 3:52pm »

thanks ariel.
 
now i at least got the damn thing running (looping that is)... yey! try/catch!
 
anyway, this is where i am at:
 
Code:

BImage img;
File jpegFile;
Metadata metadata;
 
void setup(){
  size(640, 480);  
  jpegFile = new File("P2140002.JPG");
  img = loadImage("P2140002.JPG");
}
 
void loop(){
  image(img, 0, 0);
 
  try{
    metadata = JpegMetadataReader.readMetadata(jpegFile);
 
    // ------------- PARSE DATA --------------- //
    // iterate through metadata directories
    Iterator directories = metadata.getDirectoryIterator();
    while (directories.hasNext()) {
 Directory directory = (Directory)directories.next();
 // iterate through tags and print to System.out
 Iterator tags = directory.getTagIterator();
 while (tags.hasNext()) {
   Tag tag = (Tag)tags.next();
   // use Tag.toString()
   System.out.println(tag);
 }
    }
  }
   
  catch(JpegProcessingException e){
    println("an error occured :(");
  }
}

 
since this is new territory for me (bringing in external classes like this) i am a bit stuck at this point - how can i debug what is going wrong?
 
btw. the .jar file i am using can be found here:
http://www.drewnoakes.com/code/exif/metadata-extractor-2.2.2.jar
 
and the image i am trying to get information from is this one:  
http://proce55ing.beyondthree.com/testing/exif/P2140002.JPG
 
+ mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
arielm

WWW
Re: pulling exif / iptc data from jpegs (???)
« Reply #3 on: Feb 18th, 2004, 9:48pm »

you didn't mention any new error that you are receiving so it's hard to help,
 
but anyway, why putting all this inside loop() instead of setup()? (using println() or System.out.println() there is not recommended in general)
 

Ariel Malka | www.chronotext.org
Pages: 1 

« Previous topic | Next topic »