EXIF stamp help

Discussion in 'General Discussion' started by PGB, Jan 28, 2005.

  1. PGB

    PGB

    Jan 25, 2005
    Hello,

    I have gotten this exif stamp off of DPR and am havning some issues with it. For one, it is not displaying my ISO sensitivity properly. Can anyone look at this code to see if they see the problem?

    Also you can see one of the images with my exif stamp on it.

    function explodeArray(item, delimiter) {
    tempArray = new Array(1);
    var Count = 0;
    var tempString = new String(item);
    while (tempString.indexOf(delimiter)>0) {
    tempArray[Count] = tempString.substr(0,tempString.indexOf(delimiter));
    tempString = tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
    Count = Count+1
    }
    tempArray[Count] = tempString;
    return tempArray;
    }


    function Trim(TRIM_VALUE) {
    if(TRIM_VALUE.length < 1) {
    return "";
    }
    TRIM_VALUE = RTrim(TRIM_VALUE);
    TRIM_VALUE = LTrim(TRIM_VALUE);
    if(TRIM_VALUE == "") {
    return "";
    } else {
    return TRIM_VALUE;
    }
    }


    function RTrim(VALUE) {
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    if(v_length < 0){
    return "";
    }

    var iTemp = v_length -1;
    while(iTemp > -1) {
    if(VALUE.charAt(iTemp) == w_space) {
    } else {
    strTemp = VALUE.substring(0,iTemp +1);
    break;
    }
    iTemp = iTemp-1;
    }
    return strTemp;
    }


    function LTrim(VALUE) {
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    if(v_length < 1) {
    return "";
    }

    var iTemp = 0;
    while(iTemp < v_length) {
    if(VALUE.charAt(iTemp) == w_space) {
    } else {
    strTemp = VALUE.substring(iTemp,v_length);
    break;
    }
    iTemp = iTemp + 1;
    }
    return strTemp;
    }


    function parseCaption(item) {
    var tempString = new String(item);
    // get rid of initial string [#Beginning of Shooting Data Section]
    if(tempString.indexOf("]")>0) {
    tempString=tempString.substr(tempString.indexOf("]")+1,tempString.length-tempString.indexOf("]")+1);
    }
    // get rid of final string [#End of Shooting Data Section]
    if(tempString.indexOf("[")>0) {
    tempString=tempString.substr(0,tempString.indexOf("["));
    }
    return tempString;
    }


    function splitCaption(item) {
    tempArray1 = new Array(1);
    var Count = 0;
    var tempArray2 = item.split("\x0A");
    // exclude empty elements from array
    for(n = 0; n < tempArray2.length; n = n + 1 ) {
    if (tempArray2[n].length>0) {
    tempArray1[Count]=tempArray2[n];
    Count = Count + 1;
    }
    }
    return tempArray1;
    }


    function getArrayValue(inputArray,searchString) {
    for(n = 0; n < inputArray.length; n = n + 1 ) {
    if (inputArray[n].indexOf(":")>0) {
    tempArray =inputArray[n].split(":");
    if (tempArray[0]==searchString) {
    return Trim(tempArray[1]);
    }
    }
    }
    return "";
    }


    function isZoom(item, search) {
    var tArray = item.split(" ");
    for(n = 0; n < tArray.length; n = n + 1) {
    searchPos = tArray[n].indexOf(search);
    if (searchPos > -1) {
    if(isNaN(tArray[n].substring(0, searchPos-1)) || isNaN(tArray[n].substring(searchPos+1, 999))) {
    return 1;
    }
    }
    }
    return 0;
    }


    displayDialogs = DialogModes.NO;

    var defaultRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.PIXELS;

    var AD = activeDocument;

    var resRatio = AD.resolution/IMAGE_DPI;
    if(resRatio != 1){
    AD.resizeImage(AD.width.value,AD.height.value,IMAGE_DPI);
    }

    backgroundColor = FRAME_COLOR;

    var heightOriginal = AD.height.value;
    var widthOriginal = AD.width.value;

    var frameVar = heightOriginal;
    if(widthOriginal > heightOriginal) {
    frameVar = widthOriginal;
    }
    bottomThickness = TEXT_COPYRIGHT_SIZE+(TEXT_INFO_SIZE*3)+(2/100*frameVar);

    AD.resizeCanvas(AD.width.value+(FRAME_THICKNESS*frameVar), AD.height.value+(FRAME_THICKNESS*frameVar), AnchorPosition.MIDDLECENTER);
    var heightVar = heightOriginal+(FRAME_THICKNESS*frameVar*0.80);
    AD.resizeCanvas(AD.width.value, AD.height.value+bottomThickness, AnchorPosition.TOPCENTER);


    var cameraModel = "";
    var focalLength = "";
    var sensitivity = "";
    var dateTaken = "";
    var yearTaken = "";
    var meteringMode = "";
    var optimizeImage = "";
    var colorMode = "";
    var noiseReduction = "";
    var exposureTime = "";
    var exposureAperture = "";
    var exposureMode = "";
    var whiteBalance = "";
    var toneComp = "";
    var pictureQuality1 = "";
    var pictureQuality2 = "";
    var afMode = "";
    var hueAdjustment = "";
    var imageSize = "";
    var flash = "";
    var flashSyncMode = "";
    var flashAutoMode = "";
    var flashAutoComp = "";
    var flashHead = "";
    var saturation = "";
    var exposureComp = "";
    var sharpening = "";
    var lens = "";
    var imageComment = "";
    var isJPEG = false;


    // parse standard EXIF data
    var exifData = AD.info.exif.toString();
    exifArray = explodeArray(exifData,",");

    for(n = 0; n < exifArray.length; n = n + 2 ) {
    if(exifArray[n] == "Model") {
    cameraModel = exifArray[n+1];
    }
    if(exifArray[n] == "Focal Length") {
    focalLength = parseInt(exifArray[n+1]);
    }
    if(exifArray[n].indexOf("Exposure Time") != -1) {
    exposureTime = exifArray[n+1];
    }
    if(exifArray[n].indexOf("F-Stop") != -1) {
    exposureAperture = exifArray[n+1];
    }
    if(exifArray[n].indexOf("ISO Speed Ratings") != -1) {
    sensitivity = exifArray[n+1];
    }
    if(exifArray[n].indexOf("Exposure Bias Value") != -1) {
    exposureComp = exifArray[n+1];
    }
    if(exifArray[n].indexOf("Date Time Original") != -1) {
    dateTaken = exifArray[n+1];
    var dateArray1 = dateTaken.split(" ", 1);
    dateTaken = dateArray1[0];
    var dateArray2 = dateTaken.split(":");
    var monthsArray =["January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"];
    dateTaken = dateArray2[2]+" "+monthsArray[dateArray2[1]-1]+" "+dateArray2[0];
    yearTaken = dateArray2[0];
    }
    if(exifArray[n].indexOf("Exposure Program") != -1) {
    exposureMode = exifArray[n+1];
    }
    if(exifArray[n].indexOf("Metering Mode") != -1) {
    meteringMode = exifArray[n+1];
    }
    if(exifArray[n].indexOf("Flash") != -1) {
    flash = parseInt(exifArray[n+1],10);
    }
    if(exifArray[n].indexOf("Color Space") != -1) {
    colorMode = exifArray[n+1];
    }
    }


    // parse EXIF caption data
    var captionData = Trim(AD.info.caption);

    if(captionData != "") {
    var captionArray = splitCaption(parseCaption(captionData));

    cameraModel = captionArray[0];
    focalLength = getArrayValue(captionArray,"Focal Length");
    optimizeImage = getArrayValue(captionArray,"Optimize Image");
    //colorMode = getArrayValue(captionArray,"Color Mode");
    noiseReduction = getArrayValue(captionArray,"Noise Reduction");
    exposureMode = getArrayValue(captionArray,"Exposure Mode");
    whiteBalance = getArrayValue(captionArray,"White Balance");
    toneComp = getArrayValue(captionArray,"Tone Comp");
    pictureQuality1 = captionArray[9];
    pictureQuality2 = captionArray[10];
    afMode = getArrayValue(captionArray,"AF Mode");
    hueAdjustment = getArrayValue(captionArray,"Hue Adjustment");
    imageSize = getArrayValue(captionArray,"Image Size");
    flashSyncMode = getArrayValue(captionArray,"Flash Sync Mode");
    flashAutoMode = getArrayValue(captionArray,"Auto Flash Mode");
    flashAutoComp = getArrayValue(captionArray,"Auto Flash Comp");
    saturation = getArrayValue(captionArray,"Saturation");
    exposureComp = getArrayValue(captionArray,"Exposure Comp.");
    sharpening = getArrayValue(captionArray,"Sharpening");
    lens = getArrayValue(captionArray,"Lens");
    sensitivity = getArrayValue(captionArray,"Sensitivity");
    imageComment = getArrayValue(captionArray,"Image Comment");
    }


    // custom EXIF layout over standard
    if(meteringMode == "Pattern") {
    meteringMode = "Matrix";
    }
    if(meteringMode == "Center Weighted Average") {
    meteringMode = "CWA";
    }
    if(afMode == "Manual") {
    afMode = "MF";
    }
    var pqArray1 = pictureQuality1.split(" ");
    var pqArray2 = pictureQuality2.split(" ");
    if(pqArray1[0] == "RAW" || pqArray1[0] == "JPEG") {
    pictureQuality = pqArray1[0] + " " + pqArray1[1];
    } else if(pqArray2[0] == "RAW" || pqArray2[0] == "JPEG") {
    pictureQuality = pqArray2[0] + " " + pqArray2[1];
    flashHead = pictureQuality1;
    } else {
    pictureQuality = "";
    }
    if(pqArray1[0] == "JPEG" || pqArray2[0] == "JPEG") {
    isJPEG = true;
    }


    var newLens = prompt("Lens found: " + lens + "\n\nCorrect it if you want:", lens);
    if(newLens != null) {
    lens = newLens;
    }


    var copyrightText = "\u00A9" + yearTaken + " " + SIGNATURE;

    var infoText = "";

    if(cameraModel != "") {
    infoText = infoText + cameraModel;
    }
    if(lens != "") {
    if(cameraModel != "") {
    infoText = infoText + " with " + lens;
    } else {
    infoText = infoText + lens;
    }
    }
    if(focalLength != "" && isZoom(lens, "-")) {
    infoText = infoText + " @" + focalLength;
    } else {
    if(lens == "") {
    infoText = infoText + ", " + focalLength + "mm focals";
    }
    }
    infoText = infoText + "\u000D";
    if(exposureMode != "" && exposureMode != "Not defined") {
    infoText = infoText + exposureMode + " ";
    }
    if(exposureTime != "") {
    infoText = infoText + exposureTime + " ";
    }
    if(exposureAperture != "") {
    infoText = infoText + exposureAperture + " ";
    }
    if(exposureComp != "0 EV" && exposureComp != "0.00" && exposureComp != "") {
    infoText = infoText + exposureComp + " ";
    }
    if(meteringMode != "") {
    infoText = infoText + "using " + meteringMode +" metering";
    }
    if(sensitivity != "") {
    infoText = infoText + ", " + sensitivity;
    }
    infoText = infoText + " \u000D";
    if(dateTaken != "") {
    infoText = infoText + dateTaken;
    }
    if(pictureQuality != "") {
    infoText = infoText + ", " + pictureQuality;
    }
    if(isJPEG) {
    if(colorMode != "") {
    infoText = infoText + ", " + colorMode;
    }
    if(sharpening != "") {
    infoText = infoText + ", " + sharpening + " sharpening";
    }
    if(saturation != "") {
    infoText = infoText + ", " + saturation + " saturation";
    }
    if(hueAdjustment != "") {
    infoText = infoText + ", Hue " + hueAdjustment;
    }
    if(toneComp != "") {
    infoText = infoText + ", " + toneComp;
    }
    }
    if(whiteBalance != "") {
    infoText = infoText + ", WB " + whiteBalance;
    }
    if(afMode != "") {
    infoText = infoText + ", " + afMode + " mode";
    }
    if(flash > 0) {
    if(flashAutoMode != "") {
    infoText = infoText + ", " + flashAutoMode;
    done = 1;
    }
    if(flashAutoComp != "0 EV" && flashAutoComp != "") {
    infoText = infoText + " " + flashAutoComp;
    done = 1;
    }
    if(flashHead != "") {
    infoText = infoText + " " + flashHead;
    done = 1;
    }
    }



    Thanks for your help,

    14891493-L.
     
  2. Hey, Patrick, hope you have gotten my email with "the Hack".

    There are two problems I have found with all of the scripts as posted. The first surfaced with my images. I use Digital Pro to transfer my images and it build a Description field which just happens to have an embedded comma ",". This causes a problem because the script uses the comma as a delimiter for the fields, then expects then to all start on even numbered boundaries. I have a fix for this which figures out where to start. The problem Patrick is seeing is because, at some point just before White Balance, the EXIF string gets off by 1. Here is the "quick and dirty" hack, you can insert this as appropriate. I am working on a more generic fix which I will then pass on to the Script Writers such as Federico for inclusion in his next releases. Be aware that because at least 2 fields, Description and Copyright, may contain free-form data, there may still be issues.

    Dewey's Hack for Patrick's ISO problem. The first three lines are the original and should remain. Comment out, or remove, the alert, it is only there for debugging purposes.

    if(exifArray[n].indexOf("ISO Speed Ratings") != -1) {
    sensitivity = exifArray[n+1];
    }

    /* Bad hack by Bill Dewey for Test Only */
    if ( n+1 < exifArray.length) {
    var stringTemp2=exifArray[n+1]
    }
    if(stringTemp2.indexOf("ISO Speed Ratings")!=-1){
    sensitivity = exifArray[n+2];
    alert ("sensitivity now set =:"+sensitivity+":");
    }
     
Loading...
Similar Threads Forum Date
Exif Data In Posted Images General Discussion Sep 6, 2015
Adding name to exif data - stolen gear recovered. General Discussion Jul 10, 2015
EXIF viewer that shows focus or subject distance? General Discussion Feb 22, 2015
Photography and Stamps. General Discussion Apr 10, 2013
KUSO Exif Reader General Discussion Mar 16, 2013