• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Setting xmp ISOSpeedRatings property

New Here ,
Jun 24, 2012 Jun 24, 2012

Copy link to clipboard

Copied

Hello, I was wondering if anyone could help me with a problem I was having with setting the ISO Speed exif property for a basic raw to jpeg converter I was working on.  I'm able to set other exif properties successfully, such as exposure time, focal length, etc. but I was having problems with the ISOSpeedRatings property, since the ISO in the converted jpeg just returns 0.

Here's the function I have for setting the properties -

function setImageEXIF(fileName,MK,ML,ET,FN,IS,FL,EV){

    if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

    var xmpf = new XMPFile(fileName.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE | XMPConst.OPEN_USE_SMART_HANDLER );

    var xmp = xmpf.getXMP();

    try{

        xmp.setProperty(XMPConst.NS_TIFF, 'Make', MK);

        xmp.setProperty(XMPConst.NS_TIFF, 'Model', ML);

        xmp.setProperty(XMPConst.NS_EXIF, 'ExposureTime', ET);

        xmp.setProperty(XMPConst.NS_EXIF, 'FNumber', FN);

        xmp.setProperty(XMPConst.NS_EXIF, 'ISOSpeedRatings', IS);

        xmp.setProperty(XMPConst.NS_EXIF, 'FocalLength', FL);

        xmp.setProperty(XMPConst.NS_CAMERA_RAW, 'Exposure2012', Number(EV));

        if (xmpf.canPutXMP(xmp)) {

                xmpf.putXMP(xmp);

            }else{

                alert(e.message);

            }

            xmpf.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

    }catch(e){}

}

I tried setting the ISO property from a string and a number value. The property is being set from an edit text box, just like the other exif properties.  Here's the full script -

#target photoshop

app.bringToFront();

main();

function main(){

    // ------------------------------------------------------------------------- UI

    Prefs = {};

    try{

        var desc1 = app.getCustomOptions('0bafbed0-0bc7-11e1-be50-0800200c9a66');

        Prefs = eval(desc1.getString(0));

    }catch(e){

        Prefs.folder1 = Folder("~/desktop");

        Prefs.folder2 = Folder("~/desktop");

        Prefs.bits = false;

    }

    // ------------------------------------- General graphics

    var win = new Window( 'dialog', 'RAW Converter' );

    g = win.graphics;

    var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.91, 0.91, 0.91, 1]);

    g.backgroundColor = myBrush;

    win.orientation = 'row';

    win.p1 = win.add("panel", undefined, undefined, {borderStyle:"etched"});

    win.g1 = win.p1.add('group');

    win.g1.orientation = "row";

    win.title = win.g1.add('statictext',undefined,'RAW Converter');

    win.title.alignment = "fill";

    var g = win.title.graphics;

    g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);

    // ------------------------------------- Input section

    win.g5 = win.p1.add('group');

    win.g5.orientation = "row";

    win.g5.alignment = 'left';

    win.g5.spacing = 10;

    win.g5.st1 = win.g5.add('statictext',undefined,'Input Folder');

    var g_5 = win.g5.st1.graphics;

    g_5.font = ScriptUI.newFont("Georgia","BOLD",14);

    win.g10 = win.p1.add('group');

    win.g10.orientation = "row";

    win.g10.alignment = 'left';

    win.g10.spacing = 10;

    win.g10.et1 = win.g10.add('edittext');      

    win.g10.et1.preferredSize = [400,20];

    win.g10.et1.enabled = false;

    win.g10.bu1 = win.g10.add('button',undefined,'Browse');

    win.g10.bu1.onClick = function() {

        InputFolder = Folder.selectDialog("Input folder",Prefs.folder1);

        // Exposure folders which will be used for input (total of 5 will be used)

        if(InputFolder != null){

            win.g10.et1.text = decodeURI(InputFolder.fsName);

        }

    }

    // ------------------------------------- Output section

    win.g15 = win.p1.add('group');

    win.g15.orientation = "row";

    win.g15.alignment = 'left';

    win.g15.spacing = 10;

    win.g15.st1 = win.g15.add('statictext',undefined,'Output Folder');

    var g15 = win.g15.st1.graphics;

    g15.font = ScriptUI.newFont("Georgia","BOLD",14);

    win.g20 = win.p1.add('group');

    win.g20.orientation = "row";

    win.g20.alignment = 'left';

    win.g20.spacing = 10;

    win.g20.et1 = win.g20.add('edittext');

    win.g20.et1.preferredSize = [400,20];

    win.g20.et1.enabled = false;

    win.g20.bu1 = win.g20.add('button',undefined,'Browse');

    win.g20.bu1.onClick = function() {

        OutputFolder = Folder.selectDialog("Output folder",Prefs.folder2);

        if(OutputFolder != null){

            win.g20.et1.text = decodeURI(OutputFolder.fsName);

        }

    }

    // ------------------------------------- XMP

    win.g40 = win.p1.add('group');

    win.g40.orientation = "row";

    win.g40.alignment = 'left';

    win.g40.st1 = win.g40.add('statictext',undefined,'XMP Input');

    var g_40 = win.g40.st1.graphics;

    g_40.font = ScriptUI.newFont("Georgia","BOLD",14);

    // ------------------------------------- XMP (Exposure Value)

    win.g41 = win.p1.add('group');

    win.g41.orientation = "row";

    win.g41.alignment = 'left';

    win.g41.spacing = 10;

    win.g41.et1 = win.g41.add('edittext',undefined,'0');

    win.g41.st2 = win.g41.add('statictext',undefined,'Exposure Value');

    win.g41.et1.preferredSize=[80,20];

    win.g41.et1.enabled = true;

    win.g41.et1.helpTip = "The value which is used to calculate the resulting exposure value for each file's xmp. If a multiple bracket type is choosen for the input or output, all of the brackets will be offset from that value.";

    // ------------------------------------- EXIF

    win.g50 = win.p1.add('group');

    win.g50.orientation = "row";

    win.g50.alignment = 'left';

    win.g50.st1 = win.g50.add('statictext',undefined,'EXIF Output');

    var g_40 = win.g50.st1.graphics;

    g_40.font = ScriptUI.newFont("Georgia","BOLD",14);

    // ------------------------------------- EXIF (Make)

    win.g51 = win.p1.add('group');

    win.g51.orientation = "row";

    win.g51.alignment = 'left';

    win.g51.spacing = 10;

    win.g51.et1 = win.g51.add('edittext',undefined,'Canon');

    win.g51.st2 = win.g51.add('statictext',undefined,'Make');

    win.g51.et1.preferredSize=[200,20];

    win.g51.et1.enabled = true;

    win.g51.et1.helpTip = "The camera's manufacturer";

    // ------------------------------------- EXIF (Model)

    win.g52 = win.p1.add('group');

    win.g52.orientation = "row";

    win.g52.alignment = 'left';

    win.g52.spacing = 10;

    win.g52.et1 = win.g52.add('edittext',undefined,'Canon EOS REBEL T1i');

    win.g52.st2 = win.g52.add('statictext',undefined,'Model');

    win.g52.et1.preferredSize=[200,20];

    win.g52.et1.enabled = true;

    win.g52.et1.helpTip = "The camera model";

    // ------------------------------------- EXIF (Exposure Time)

    win.g53 = win.p1.add('group');

    win.g53.orientation = "row";

    win.g53.alignment = 'left';

    win.g53.spacing = 10;

    win.g53.et1 = win.g53.add('edittext',undefined,'1');

    win.g53.st2 = win.g53.add('statictext',undefined,'Exposure Time');

    win.g53.et1.preferredSize=[80,20];

    win.g53.et1.enabled = true;

    win.g53.et1.helpTip = "The value which is used to calculate the resulting exposure time for each file's exif. If a multiple bracket is choosen for the input or output, this value will be entered into the middle exposure for each bracket set, and the other files' exposure time is calculated from that. This value can be either a decimal or fraction, such as 0.25 or 1/4";

    // ------------------------------------- EXIF (F Stop)

    win.g54 = win.p1.add('group');

    win.g54.orientation = "row";

    win.g54.alignment = 'left';

    win.g54.spacing = 10;

    win.g54.et1 = win.g54.add('edittext',undefined,'110/10');

    win.g54.st2 = win.g54.add('statictext',undefined,'F Stop');

    win.g54.et1.preferredSize=[80,20];

    win.g54.et1.enabled = true;

    win.g54.et1.helpTip = "The aperature used with the image";

    // ------------------------------------- EXIF (ISO)

    win.g55 = win.p1.add('group');

    win.g55.orientation = "row";

    win.g55.alignment = 'left';

    win.g55.spacing = 10;

    win.g55.et1 = win.g55.add('edittext',undefined,'100');

    win.g55.st2 = win.g55.add('statictext',undefined,'ISO');

    win.g55.et1.preferredSize=[80,20];

    win.g55.et1.enabled = true;

    win.g55.et1.helpTip = "The ISO speed used with the image";

    // ------------------------------------- EXIF (Focal Length)

    win.g56 = win.p1.add('group');

    win.g56.orientation = "row";

    win.g56.alignment = 'left';

    win.g56.spacing = 10;

    win.g56.et1 = win.g56.add('edittext',undefined,'35');

    win.g56.st2 = win.g56.add('statictext',undefined,'Focal Length');

    win.g56.et1.preferredSize=[80,20];

    win.g56.et1.enabled = true;

    win.g56.et1.helpTip = "The focal length used with the image";

    // ------------------------------------- Process

    win.g300 = win.p1.add('group');

    win.g300.orientation = "row";

    win.g300.alignment = 'center';

    win.g300.spacing = 10;

    win.g300.bu1 = win.g300.add('button',undefined,'Process');

    win.g300.bu1.preferredSize = [240,30];

    win.g300.bu2 = win.g300.add('button',undefined,'Cancel');

    win.g300.bu2.preferredSize = [240,30];

    win.g300.bu1.onClick = function() {

        if(win.g10.et1.text == ''){

            alert("Input folder has not been selected!");

            return

        }

        if(win.g20.et1.text == ''){

            alert("Output folder has not been selected!");

            return

        }

        try{

        // --------------- Prefs start

        Prefs.folder1 = InputFolder;

        Prefs.folder2 = OutputFolder;

        var count = 0;

        // --------------- Progress Bar

        var progressBar = function(title) {

            var w = new Window( 'palette', ' '+title, {x:0, y:0, width:340, height:60} ),

            pb = w.add( 'progressbar', {x:20, y:12, width:300, height:12}, 0, 100 ),

            st = w.add( 'statictext', {x:10, y:36, width:320, height:20}, '' );

            st.justify = 'center';

            w.center();

            this.reset = function( msg,maxValue ) {

                st.text = msg;

                pb.value = 0;

                pb.maxvalue = maxValue||0;

                pb.visible = !!maxValue;

                w.show();

            };

            this.hit = function() { ++pb.value; };

            this.hide = function() { w.hide(); };

            this.close = function() { w.close(); };

            this.show = function() { w.show(); };

            this.update = function() { w.update(); };

            this.layout = function() { w.layout.layout(); };

        };

        function doPbar(){

            pBar.hit();

            pBar.hide();

            pBar.show();

        }

        var PBarTitle = "RAW Conversion";

        // --------------- Process files and folders

        var group0 = InputFolder.getFiles(/\.(dng|crw|cr2|raw|raf|3fr|dcr|kdc|mrw|nef|nrw|orf|rw2|pef|x3f|srf|sr2)$/i); // Single conversion files

        count += group0.length;

        if (count <1) return;

        var pBar = new progressBar(PBarTitle);

        pBar.reset("Processing Files", (group0.length*1));

        var MakeVar = win.g51.et1.text.toString(); // Camera Make

        var ModelVar = win.g52.et1.text.toString(); // Camera Model

        var ExposureTimeVar = win.g53.et1.text.toString(); // Middle exposure time

        var ExposureValueVar = eval(win.g41.et1.text.toString()); // Offset exposure value

        var FNumberVar = win.g54.et1.text.toString(); // FNumber

        var ISOSpeedVar = win.g55.et1.text.toString(); // ISO

        var FocalLengthVar = win.g56.et1.text.toString(); // Focal Length

        // ------------------ Save files function

        function SaveRAW(thumb,FileName,Outpath,Make,Model,ExposureValue,ExposureValueOffset,ExposureTime,FNumber,ISOSpeed,FocalLength) {

            var SetExposureValue = (ExposureValueOffset + ExposureValue);

            if (SetExposureValue > 5) SetExposureValue = 5;

            if (SetExposureValue < -5) SetExposureValue = -5;

            setRAWEV(thumb,SetExposureValue);

            open(thumb);

            var exportFile = new File( Outpath + "/" + FileName + ".jpg" );

            SaveAsJPEG(exportFile,100);

            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

            setRAWEV(thumb,0);

            setImageEXIF(exportFile,Make,Model,ExposureTime,FNumber,ISOSpeed,FocalLength,SetExposureValue);

            doPbar();

        };

        // ------------------ Save Files

        for(var z in group0) {

            var Name = decodeURI(group0.name).replace(/\.[^\.]+$/, '');

            SaveRAW(group0,Name,OutputFolder,MakeVar,ModelVar,0,ExposureValueVar,ExposureTimeVar,"1",FNumberVar,ISOSpeedVar,FocalLengthVar);

        }

        // --------------- Prefs end

        var desc2 = new ActionDescriptor();

        desc2.putString(0, Prefs.toSource());

        app.putCustomOptions('0bafbed0-0bc7-11e1-be50-0800200c9a66', desc2, true );

        win.close(0);

        }catch(e){alert(e + " - " +e.line);}

    }

    win.center();

    win.show();

    app.displayDialogs = DialogModes.NO;

}

// ----------------------------------------------------------------------------- Functions

function setRAWEV(thumb,evValue){

    var Name = decodeURI(thumb.name).replace(/\.[^\.]+$/, '');

    var file = new File(thumb.path + "/" + Name + ".xmp");

    try{

        if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

        if(file.exists){

            file.open('r');

            file.encoding = "UTF8";

            file.lineFeed = "unix";

            file.open("r", "TEXT", "????");

            var xmpStr = file.read();

            file.close();

        }else{

            var xmpStr='';

        }

        var xmp = new XMPMeta( xmpStr );

        var exposureValue = xmp.getProperty(XMPConst.NS_CAMERA_RAW, "Exposure2012");

        xmp.deleteProperty(XMPConst.NS_CAMERA_RAW, "Exposure2012");

        xmp.setProperty(XMPConst.NS_CAMERA_RAW, "Exposure2012",Number(evValue));

        file.open('w');

        file.encoding = "UTF8";

        file.lineFeed = "unix";

        file.write( xmp.serialize() );

        file.close();

        if(exposureValue == undefined) exposureValue = 0;

    }catch(e){alert(e+"-"+e.line);}

    return exposureValue;

}; // Set exposure time to raw file's xmp

function setImageEXIF(fileName,MK,ML,ET,FN,IS,FL,EV){

    if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

    var xmpf = new XMPFile(fileName.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE | XMPConst.OPEN_USE_SMART_HANDLER );

    var xmp = xmpf.getXMP();

    try{

        xmp.setProperty(XMPConst.NS_TIFF, 'Make', MK);

        xmp.setProperty(XMPConst.NS_TIFF, 'Model', ML);

        xmp.setProperty(XMPConst.NS_EXIF, 'ExposureTime', ET);

        xmp.setProperty(XMPConst.NS_EXIF, 'FNumber', FN);

        xmp.deleteProperty(XMPConst.NS_EXIF, 'ISOSpeedRatings');

        xmp.setProperty(XMPConst.NS_EXIF, 'ISOSpeedRatings', IS);

        xmp.setProperty(XMPConst.NS_EXIF, 'FocalLength', FL);

        xmp.setProperty(XMPConst.NS_CAMERA_RAW, 'Exposure2012', Number(EV));

        if (xmpf.canPutXMP(xmp)) {

                xmpf.putXMP(xmp);

            }else{

                alert(e.message);

            }

            xmpf.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

    }catch(e){}

} // Set exif data in output files

function SaveAsJPEG(saveFile,jpegQuality) {

    var sfwOptions = new ExportOptionsSaveForWeb();

    sfwOptions.format = SaveDocumentType.JPEG;

    sfwOptions.includeProfile = false;

    sfwOptions.interlaced = 0;

    sfwOptions.optimized = true;

    sfwOptions.quality = jpegQuality;

    activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

} // Save JPEG

Does anyone know what I'm missing here?

TOPICS
Actions and scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Valorous Hero ,
Jun 24, 2012 Jun 24, 2012

Copy link to clipboard

Copied

Yes the problem is that ISOSpeedRatings is an ordered array not a string.

To get the information about the xmp of a document you can use the following code in ESTK...

#target photoshop

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

xmp = app.activeDocument.xmpMetadata.rawData;

xmpObject = new XMPMeta(xmp);

$.writeln( xmpObject.dumpObject() );


So it should be:-

xmp.appendArrayItem(XMPConst.NS_EXIF, 'ISOSpeedRatings', IS, 0,XMPConst.ARRAY_IS_ORDERED);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2012 Jun 25, 2012

Copy link to clipboard

Copied

LATEST

WOW thanks a lot man! You're like some kind of hero around here!  I did finally figure out that it was an array, but I didn't know how to access it properly.  I seems weird that it has to be an array for an ISO number.  Just like adobe changing some of the xmp settings, like changing Exposure to Exposure2012.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines