header image
Home
Pictures
Photoshop CS3 Scripts
Recipes
Links
Login Form
Username

Password

Remember me
Password Reminder
Home arrow Photoshop CS3 Scripts arrow Saves 4 image sizes with unique filenames
Saves 4 image sizes with unique filenames PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Daniel Munevar   
Sep 04, 2007 at 04:41 PM
This Photoshop CS3 script will:
Resize an image 3 times
Save for web each time, appending a character sequence each time to the first 7 characters of the filename
Step back in history
Resize a fourth time
Save the image again appending to the current filename
Close the image

This script contains scripting to:
Save for web, using specified quality and format
Change background color
Change mode to RGB
Save a selection as an alpha channel
Change DPI to 72
Use the Fit Image command
Use the Crop command
Set unit type to Pixels
Have an alert popup
Check if image is over certain size
Delete file if it exists in save directory
Select a previous history state
Run the Sharpen filter
Close image without saving
//-----------------------------------------------------------------------------------
//  Resize 3 times, step back in history, resize again, save each for web. Keyless.
//
//  Danny Munevar, 2007, http://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;
var histReturn = -4
//Save Selection if it exists as channel alpha 1
try {
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 Image
try
{
  var docRef = app.activeDocument;
  var options = new ExportOptionsSaveForWeb();
  options.quality = 80;
  options.format = SaveDocumentType.JPEG;
  var targetName = "C:\\upload\\" + docRef.name.substring(0,7) +"_e.jpg";
  // Get root name, add required extension.
  var targetFile = new File(targetName);
  if (targetFile.exists ) targetFile.remove(); // Zap it or you get overwrite prompt later.
    if (app.activeDocument.height.value > 525 || app.activeDocument.width.value > 750) {
 fitImage(750,525);
 histReturn = histReturn - 1;
    }
  app.activeDocument.activeLayer.applySharpen();
  docRef.exportDocument(targetFile, ExportType.SAVEFORWEB, options);
}
catch (e)
{
 alert("Error: " + e);
}
//end enlarged image

//Bundle Image
try
{
  var docRef = app.activeDocument;
  var options = new ExportOptionsSaveForWeb();
  options.quality = 80;
  options.format = SaveDocumentType.JPEG;
  var targetName = "C:\\upload\\" + docRef.name.substring(0,7) +"_b.jpg";
  // Get root name, add required extension.
  var targetFile = new File(targetName);
  if (targetFile.exists ) targetFile.remove(); // Zap it or you get overwrite prompt later.
  fitImage(200,300); 
   if (app.activeDocument.width.value < 200) {
    app.activeDocument.resizeCanvas(200);
 histReturn = histReturn - 1; 
 }
  app.activeDocument.activeLayer.applySharpen();
  docRef.exportDocument(targetFile, ExportType.SAVEFORWEB, options);
}
catch (e)
{
 alert("Error: " + e);
}
//end bundle image

//Product Image
try
{
  var docRef = app.activeDocument;
  var options = new ExportOptionsSaveForWeb();
  options.quality = 80;
  options.format = SaveDocumentType.JPEG;
  var targetName = "C:\\upload\\" + docRef.name.substring(0,7) +"_p.jpg";
  // Get root name, add required extension.
  var targetFile = new File(targetName);
  if (targetFile.exists ) targetFile.remove(); // Zap it or you get overwrite prompt later.
  app.activeDocument.resizeImage(150);
  //app.activeDocument.activeLayer.applySharpen();
  docRef.exportDocument(targetFile, ExportType.SAVEFORWEB, options);
}
catch (e)
{
 alert("Error: " + e);
}
//end product image

//Select history state histReturn
var id195 = charIDToTypeID( "slct" );
    var desc45 = new ActionDescriptor();
    var id196 = charIDToTypeID( "null" );
        var ref21 = new ActionReference();
        var id197 = charIDToTypeID( "HstS" );
        ref21.putOffset( id197, histReturn );
    desc45.putReference( id196, ref21 );
executeAction( id195, desc45, DialogModes.NO );
//end select history state

// 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


//Thumbnail Image
try
{
  var docRef = app.activeDocument;
  var options = new ExportOptionsSaveForWeb();
  options.quality = 80;
  options.format = SaveDocumentType.JPEG;
  var targetName = "C:\\Upload\\" + docRef.name.substring(0,7) +"_t.jpg";
  // Get root name, add required extension.
  var targetFile = new File(targetName);
  if (targetFile.exists ) targetFile.remove(); // Zap it or you get overwrite prompt later.
  fitImage(100,100); 
  app.activeDocument.resizeCanvas(100, 100);
  app.activeDocument.activeLayer.applySharpen();
  docRef.exportDocument(targetFile, ExportType.SAVEFORWEB, options);
}
catch (e)
{
 alert("Error: " + e);
}
//end 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 );
//====================================================

Last Updated ( Nov 19, 2007 at 01:28 PM )