Skip to content

Instantly share code, notes, and snippets.

@kuyseng
Created June 5, 2012 02:46
Show Gist options
  • Save kuyseng/2872224 to your computer and use it in GitHub Desktop.
Save kuyseng/2872224 to your computer and use it in GitHub Desktop.
javascript: photoshop save for web with metadata
function Cs4SFW(FileName,Quality,MetaData, Profile,Progressive) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
/*
reference -> http://forums.adobe.com/message/2582725
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 = 60;
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 );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment