File file = new File(filePath);
if (!wikiFormat && argList.size()>1)
System.out.println("***** PROCESSING: " + filePath);
Metadata metadata = null;
try {
metadata = ImageMetadataReader.readMetadata(file);
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
long took = System.nanoTime() - startTime;
if (!wikiFormat)
System.out.println("Processed " + (file.length()/(1024d*1024)) + "MB file in " + (took / 1000000d) + "ms");
if (wikiFormat) {
String fileName = file.getName();
String urlName = fileName.replace(" ", "%20"); // How to do this using framework?
ExifIFD0Directory exifIFD0Directory = metadata.getOrCreateDirectory(ExifIFD0Directory.class);
String make = escapeForWiki(exifIFD0Directory.getString(ExifIFD0Directory.TAG_MAKE));
String model = escapeForWiki(exifIFD0Directory.getString(ExifIFD0Directory.TAG_MODEL));
System.out.println();
System.out.println("-----");
System.out.println();
System.out.printf("= %s - %s =%n", make, model);
System.out.println();
System.out.printf("<a href=\"http://metadata-extractor.googlecode.com/svn/sample-images/%s\">%n", urlName);
System.out.printf("<img src=\"http://metadata-extractor.googlecode.com/svn/sample-images/%s\" width=\"300\"/><br/>%n", urlName);
System.out.println(fileName);
System.out.println("</a>");
System.out.println();
System.out.println("|| *Directory* || *Tag Id* || *Tag Name* || *Tag Description* ||");
}
// iterate over the exif data and print to System.out
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
String tagName = tag.getTagName();
String directoryName = directory.getName();
String description = tag.getDescription();
if (wikiFormat) {
System.out.printf("||%s||0x%s||%s||%s||%n",
escapeForWiki(directoryName),
Integer.toHexString(tag.getTagType()),
escapeForWiki(tagName),
escapeForWiki(description));
}
else
{
System.out.printf("[%s] %s = %s%n", directoryName, tagName, description);
}
}
// print out any errors
for (String error : directory.getErrors())
System.err.println("ERROR: " + error);
}
if (args.length > 1 && thumbRequested) {
ExifThumbnailDirectory directory = metadata.getDirectory(ExifThumbnailDirectory.class);
if (directory!=null && directory.hasThumbnailData()) {
System.out.println("Writing thumbnail...");
directory.writeThumbnail(args[0].trim() + ".thumb.jpg");
} else {
System.out.println("No thumbnail data exists in this image");