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

Password

Remember me
Password Reminder
Home arrow Photoshop CS3 Scripts arrow Makes multiple images with user inputted data
Makes multiple images with user inputted data PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Daniel Munevar   
Sep 04, 2007 at 02:21 PM

Uses for this script:
This script is useful for someone that needs to create multiple enlargeable images for an item or product. The thumbnail image can be a portion of the main image and additionally it will prompt the user for a number and text to add to the end of the thumbnail filename. This text can then be read and displayed dynamically on the webpage.

This CS3 script takes the following steps:
1. Changes the image to 72 DPI
2. Changes the background color to white
3. Changes the mode to RGB
4. Adjusts ruler units to pixels
5. Saves the current selection as an alpha channel and returns to the RGB channel
6. If image size is above 525 tall or 750 wide, resizes to fit 525 x 750. Otherwise it leaves the image size alone.
7. Sharpens the image
8. Prompts the user for an image number and text to append to the thumbnail filename
9. Save for web with the filename as follows: "First 7 digits of original filename" + "_xe" + "user inputted image number" + ".jpg". Saves to the 'C:\upload' directory
10. Loads saved marquee
11. Crops selected area
12. Sharpens the image
13. Save for web with the filename as follows: "First 7 digits of original filename" + "_xs" + "user inputted image number" + "_" + "document image width" + "user inputted text" + ".jpg"
14. Closes the image without save prompt. Saves to the 'C:\upload' directory

//-----------------------------------------------------------------------------------
// 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 );
//====================================================

Last Updated ( Sep 05, 2007 at 10:09 AM )