//-----------------------------------------------------------------------------------
// Resize and save for web CS3 - Append to filename prompt
//
// Daniel Munevar, 2007,
www.getdanny.com//
#target photoshop
// ScriptListener
//Change to 72 DPI (prevents sizing errors) ======================
var id20 = charIDToTypeID( "ImgS" );
var desc7 = new ActionDescriptor();
var id21 = charIDToTypeID( "Rslt" );
var id22 = charIDToTypeID( "#Rsl" );
desc7.putUnitDouble( id21, id22, 72.000000 );
executeAction( id20, desc7, DialogModes.NO );
// Set background color to white ===============================
var id23 = charIDToTypeID( "setd" );
var desc8 = new ActionDescriptor();
var id24 = charIDToTypeID( "null" );
var ref4 = new ActionReference();
var id25 = charIDToTypeID( "Clr " );
var id26 = charIDToTypeID( "BckC" );
ref4.putProperty( id25, id26 );
desc8.putReference( id24, ref4 );
var id27 = charIDToTypeID( "T " );
var desc9 = new ActionDescriptor();
var id28 = charIDToTypeID( "Rd " );
desc9.putDouble( id28, 255.000000 );
var id29 = charIDToTypeID( "Grn " );
desc9.putDouble( id29, 255.000000 );
var id30 = charIDToTypeID( "Bl " );
desc9.putDouble( id30, 255.000000 );
var id31 = charIDToTypeID( "RGBC" );
desc8.putObject( id27, id31, desc9 );
executeAction( id23, desc8, DialogModes.NO );
// Convert Mode to RGB =====================================
var id32 = charIDToTypeID( "CnvM" );
var desc10 = new ActionDescriptor();
var id33 = charIDToTypeID( "T " );
var id34 = charIDToTypeID( "RGBM" );
desc10.putClass( id33, id34 );
executeAction( id32, desc10, DialogModes.NO );
//=======================================================
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
//Save Selection
try {
var xtraNum = prompt ('Enter Xtra Number');
var xtraText = prompt ('Enter Text');
if (xtraNum.length == 1) {xtraNum = 0 + xtraNum;}
var activeChannels = app.activeDocument.activeChannels //remember active channels
var selRef = app.activeDocument.selection // current selection
var channelRef = app.activeDocument.channels.add(); // add alpha channel
//define fill color
var solidColorRef = new SolidColor();
solidColorRef.rgb.red = 255;
solidColorRef.rgb.green = 255;
solidColorRef.rgb.blue = 255;
app.activeDocument.selection.fill(solidColorRef);
//make the alpha channel reflect your selection
app.activeDocument.activeChannels = activeChannels; //return to RGB channel
var selection = "true";
} catch (e) {
}
//End save Selection
//Enlarged Xtra
try
{
var docRef = app.activeDocument;
var options = new ExportOptionsSaveForWeb();
options.quality = 80;
options.format = SaveDocumentType.JPEG;
if (app.activeDocument.height.value > 525 || app.activeDocument.width.value > 750) {
fitImage(750,525)
}
var targetName = "C:\\upload\\" + docRef.name.substring(0,7) + "_xe" + xtraNum + ".jpg";
var targetFile = new File(targetName);
//if (targetFile.exists ) targetFile.remove(); // Deletes file for no overwrite prompt.
app.activeDocument.activeLayer.applySharpen();
docRef.exportDocument(targetFile, ExportType.SAVEFORWEB, options);
}
catch (e)
{
alert("Error: " + e);
}
//end Enlarged Xtra
// load and crop
if (selection == "true") {
app.activeDocument.selection.load(app.activeDocument.channels.getByName("Alpha 1"),
SelectionType.REPLACE); //load selection
}
//Crop selection
var id36 = charIDToTypeID( "Crop" );
var desc6 = new ActionDescriptor();
executeAction( id36, desc6, DialogModes.NO );
//end load and crop
//Save thumbnail
try
{
var docRef = app.activeDocument;
var options = new ExportOptionsSaveForWeb();
options.quality = 80;
options.format = SaveDocumentType.JPEG;
fitImage(70,70)
app.activeDocument.resizeCanvas(70, 70);
if (xtraText == "undefined" || xtraText == "") {
var targetName = "C:\\upload\\" + docRef.name.substring(0,7) + "_xs" + xtraNum + ".jpg";
} else {
var targetName = "C:\\upload\\" + docRef.name.substring(0,7) + "_xs" + xtraNum + "_" +
app.activeDocument.width.value + "_" + xtraText + ".jpg";
}
var targetFile = new File(targetName);
//if (targetFile.exists ) targetFile.remove(); // Deletes file for no overwrite prompt.
app.activeDocument.activeLayer.applySharpen();
docRef.exportDocument(targetFile, ExportType.SAVEFORWEB, options);
}
catch (e)
{
alert("Error: " + e);
}
//end save thumbnail
function fitImage(w,h){
var fitImage = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );
var size = new ActionDescriptor();
size.putUnitDouble( charIDToTypeID( "Wdth" ), charIDToTypeID( "#Pxl" ), w );
size.putUnitDouble( charIDToTypeID( "Hght" ), charIDToTypeID( "#Pxl" ), h );
executeAction( fitImage, size, DialogModes.NO );
};
// Close image without saving - Script Listener ==================
var id35 = charIDToTypeID( "Cls " );
var desc11 = new ActionDescriptor();
var id36 = charIDToTypeID( "Svng" );
var id37 = charIDToTypeID( "YsN " );
var id38 = charIDToTypeID( "N " );
desc11.putEnumerated( id36, id37, id38 );
executeAction( id35, desc11, DialogModes.NO );
//====================================================