I'm trying to extract IPTC photo caption information from a JPEG file using Javascript. (I know I can do this server-side, but I'm looking specifically for a Javascript solution.)
I found this script, which extracts EXIF information ... but I'm not sure how to adapt it to grab IPTC data.
Are there any existing scripts that offer such functionality? If not, how would you modify the EXIF script to also parse IPTC data?
UPDATE
I've modified the EXIF script I linked above. It sorta does what I want, but it's not grabbing the right data 100 percent of the time.
After line 401, I added:
else if (iMarker == 237) {
// 0xED = Application-specific 13 (Photoshop IPTC)
if (bDebug) log("Found 0xFFED marker");
return readIPTCData(oFile, iOffset + 4, getShortAt(oFile, iOffset+2, true)-2);
}
And then elsewhere in the script, I added this function:
function readIPTCData(oFile, iStart, iLength) {
exif = new Array();
if (getStringAt(oFile, iStart, 9) != "Photoshop") {
if (bDebug) log("Not valid Photoshop data! " + getStringAt(oFile, iStart, 9));
return false;
}
var output = '';
var count = 0;
two = new Array();
for (i=0; i<iLength; i++) {
if (getByteAt(oFile, iStart + i) == 2 && getByteAt(oFile, iStart + i + 1) == 120) {
var caption = getString2At(oFile, iStart + i + 2, 800);
}
if (getByteAt(oFile, iStart + i) == 2 && getByteAt(oFile, iStart + i + 1) == 80) {
var credit = getString2At(oFile, iStart + i + 2, 300);
}
}
exif['ImageDescription'] = caption;
exif['Artist'] = credit;
return exif;
}
So let me now modify my question slightly. How can the function above be improved?