Skip to main content
Participant
February 10, 2010
Answered

Include Metadata in Save for Web JPEGS

  • February 10, 2010
  • 1 reply
  • 2598 views

I notice in Photoshop CS 4 that there is a new "Include Metadata" menu option in the SaveForWeb and Devices.

I have a Javascript which creates multiple files based on various sizes and i would like to know how i can get the Metadata from the original PSD file to be included in the JPEGS.

This is important as i have a database which reads the metadata fields to know where to place the images.

this is my ExportForWeb step

function SaveForWeb(saveFile) { 
var sfwOptions = new ExportOptionsSaveForWeb(); 
   sfwOptions.format = SaveDocumentType.JPEG; 
   sfwOptions.includeProfile = true;  //remove ICC profile from image
   sfwOptions.interlaced = 0; 
   sfwOptions.optimized = true; 
   sfwOptions.quality = 80;  //image quality has been set to high
app.activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

many thanks

Correct answer Paul Riggott

This is what I use...


function Cs4SFW(FileName,Quality,MetaData,Profile,Progressive) {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };
  /*
  Metadata:-
'MDAl'  All metadata 'MDNn'  No metadata
'MDCp'  Copywright  'MDCC' Copyright and contact
'MDAx'  All except camera info
Profile:-
'CHsR' sRGB Profile    'CHDc'  Use document profile
  */
//Set defaults
if(MetaData == undefined) MetaData = 'MDNn';
if(Quality == undefined) Quality = 80;
if(Profile == undefined) Profile = 'CHsR';
if(Progressive == undefined) Progressive = 1;

    var desc7 = new ActionDescriptor();
        var desc8 = new ActionDescriptor();
        desc8.putEnumerated( cTID('Op  '), cTID('SWOp'), cTID('OpSa') );
        desc8.putEnumerated( cTID('Fmt '), cTID('IRFm'), cTID('JPEG') );
        desc8.putBoolean( cTID('Intr'), false );
        desc8.putInteger( cTID('Qlty'), Quality );
        desc8.putInteger( cTID('QChS'), 0 );
        desc8.putInteger( cTID('QCUI'), 0 );
        desc8.putBoolean( cTID('QChT'), false );
        desc8.putBoolean( cTID('QChV'), false );
        desc8.putBoolean( cTID('Optm'), true );
        desc8.putInteger( cTID('Pass'), Progressive ); // 1 = Optimized 3 = Progressive
        desc8.putDouble( cTID('blur'), 0.000000 );
        desc8.putBoolean( cTID('EICC'), false ); //Embed Color Profile, Bool
        desc8.putBoolean( cTID('Mtt '), false );
        desc8.putInteger( cTID('MttR'), 255 );
        desc8.putInteger( cTID('MttG'), 255 );
        desc8.putInteger( cTID('MttB'), 255 );
        desc8.putBoolean( cTID('SHTM'), false );
        desc8.putBoolean( cTID('SImg'), true );
        desc8.putEnumerated( cTID('SWch'), cTID('STch'), cTID(Profile) );
        desc8.putEnumerated( cTID('SWmd'), cTID('STmd'), cTID(MetaData) );
        desc8.putBoolean( cTID('SSSO'), false );
            var list2 = new ActionList();
        desc8.putList( cTID('SSLt'), list2 );
        desc8.putBoolean( cTID('DIDr'), false );
        desc8.putPath( cTID('In  '), new File( FileName) );
    desc7.putObject( cTID('Usng'), sTID('SaveForWeb'), desc8 );
    executeAction( cTID('Expr'), desc7, DialogModes.NO );
};

1 reply

Paul Riggott
Paul RiggottCorrect answer
Inspiring
February 10, 2010

This is what I use...


function Cs4SFW(FileName,Quality,MetaData,Profile,Progressive) {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };
  /*
  Metadata:-
'MDAl'  All metadata 'MDNn'  No metadata
'MDCp'  Copywright  'MDCC' Copyright and contact
'MDAx'  All except camera info
Profile:-
'CHsR' sRGB Profile    'CHDc'  Use document profile
  */
//Set defaults
if(MetaData == undefined) MetaData = 'MDNn';
if(Quality == undefined) Quality = 80;
if(Profile == undefined) Profile = 'CHsR';
if(Progressive == undefined) Progressive = 1;

    var desc7 = new ActionDescriptor();
        var desc8 = new ActionDescriptor();
        desc8.putEnumerated( cTID('Op  '), cTID('SWOp'), cTID('OpSa') );
        desc8.putEnumerated( cTID('Fmt '), cTID('IRFm'), cTID('JPEG') );
        desc8.putBoolean( cTID('Intr'), false );
        desc8.putInteger( cTID('Qlty'), Quality );
        desc8.putInteger( cTID('QChS'), 0 );
        desc8.putInteger( cTID('QCUI'), 0 );
        desc8.putBoolean( cTID('QChT'), false );
        desc8.putBoolean( cTID('QChV'), false );
        desc8.putBoolean( cTID('Optm'), true );
        desc8.putInteger( cTID('Pass'), Progressive ); // 1 = Optimized 3 = Progressive
        desc8.putDouble( cTID('blur'), 0.000000 );
        desc8.putBoolean( cTID('EICC'), false ); //Embed Color Profile, Bool
        desc8.putBoolean( cTID('Mtt '), false );
        desc8.putInteger( cTID('MttR'), 255 );
        desc8.putInteger( cTID('MttG'), 255 );
        desc8.putInteger( cTID('MttB'), 255 );
        desc8.putBoolean( cTID('SHTM'), false );
        desc8.putBoolean( cTID('SImg'), true );
        desc8.putEnumerated( cTID('SWch'), cTID('STch'), cTID(Profile) );
        desc8.putEnumerated( cTID('SWmd'), cTID('STmd'), cTID(MetaData) );
        desc8.putBoolean( cTID('SSSO'), false );
            var list2 = new ActionList();
        desc8.putList( cTID('SSLt'), list2 );
        desc8.putBoolean( cTID('DIDr'), false );
        desc8.putPath( cTID('In  '), new File( FileName) );
    desc7.putObject( cTID('Usng'), sTID('SaveForWeb'), desc8 );
    executeAction( cTID('Expr'), desc7, DialogModes.NO );
};

PatchUserAuthor
Participant
February 10, 2010

Brilliant!!, this works a treat. My users will be happy.

Q: Will this work in CS3 as well or just cs4?

and which Adobe documentation do i need to read to find out about these?

I have the Photoshop Javascript reference but can't seem to find anything related to this.

once again cheers

Paul Riggott
Inspiring
February 10, 2010

No this w'ont work in CS3 as metadata is only supported in CS4. You will need to install the ScriptListener plugin and then utilize the output from the created log.

In CS3/4 the log file is created on the desktop.

There is a bit of a writeup here..

http://www.kirupa.com/motiongraphics/scripting5.htm