Click to See Complete Forum and Search --> : POST: PhotoShop CS4 xResizer Script


ehime
09-17-2009, 01:17 PM
Maybe someone can use this :confused:
No section for it, but its pretty much JavaScript.

(About)
Created a new Photoshop script to automate my tasks, this will take either the current image I am editing (or an existing saved image) compare if it is dividable by 540sqr, reject if not. If all is good, search for a ini file (writes each cycle) that tells it a known directory, then will resize and resave under
4 different extensions

540x - Big (no ext)
170x -m
50x -sm
20x -ico



#target photoshop
function main(){
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,650,280],"+
"panel0:Panel{bounds:[10,10,540,170] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"useFile:Checkbox{bounds:[10,10,200,30] , text:'Use Current Image' },"+
"statictext0:StaticText{bounds:[10,40,111,60] , text:'Select Input' ,properties:{scrolling:undefined,multiline:undefined}},"+
"jpeg:EditText{bounds:[150,40,430,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse0:Button{bounds:[440,40,521,60] , text:'Browse' },"+
"statictext1:StaticText{bounds:[10,70,140,90] , text:'Select Output' ,properties:{scrolling:undefined,multiline:undefined}},"+
"folder:EditText{bounds:[150,70,430,90] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse1:Button{bounds:[440,70,520,90] , text:'Browse' },"+
"statictext2:StaticText{bounds:[10,100,130,120] , text:'Select Rename' ,properties:{scrolling:undefined,multiline:undefined}},"+
"name:EditText{bounds:[150,100,430,120] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"button2:Button{bounds:[10,130,260,150] , text:'Ok' },"+
"button3:Button{bounds:[270,130,520,150] , text:'Cancel' }}};";

var win = new Window(dlg,"Ehime Resize Pics");
win.center();
Init();
win.panel0.jpeg.enabled = false;
win.panel0.folder.enabled = false;

win.panel0.Browse0.onClick = function() {
selectedFile = File.openDialog("Please select JPEG.","JPG File:*.jpg");
if(selectedFile !=null){
win.panel0.jpeg.text = decodeURI(selectedFile.fsName);
}
}

win.panel0.Browse1.onClick = function() {
outputFolder = Folder.selectDialog("Please select OUTPUT folder.",existFolder);
if(outputFolder !=null){
win.panel0.folder.text = decodeURI(outputFolder.fsName);
}
}

if(documents.length) {
win.panel0.useFile.value=true;
win.panel0.Browse0.enabled=false;
}else{
win.panel0.useFile.enabled=false;
}
win.panel0.useFile.onClick = function() {
if(win.panel0.useFile.value){
win.panel0.Browse0.enabled=false;
}else{
win.panel0.Browse0.enabled=true;
}
}
var done = false;
while (!done) {
var x = win.show();
if (x == 0 || x == 2) {
win.canceled = true;
done = true;
} else if (x == 1) {
done = true;
var result = validate();
if(result != true) {
alert(result);
return;
}else
{
processPic();
}
}
}
function validate(){
var Ini = new File("~/rememberFolder.ini");
if(outputFolder != ''){
Ini.open("w");
Ini.writeln(outputFolder);
Ini.close();
}
if(!win.panel0.useFile.value){
if(win.panel0.jpeg.text == '') return 'No JPEG file selected';
}
if(win.panel0.folder.text == '') return 'No Output Folder selected';
if(win.panel0.name.text == '') return 'No FileName Supplied';
return true;
}
function processPic(){
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
if(!win.panel0.useFile.value){
var file = new File(selectedFile);
open(file);
}
var doc = activeDocument;
if(doc.width.value != doc.height.value){
alert("Error: Incorrect input proportions!");
return;
}
resize(540);
activeDocument.activeLayer.duplicate ();
activeDocument.activeLayer = app.activeDocument.artLayers[0];
app.activeDocument.activeLayer.opacity=60;
app.activeDocument.activeLayer.blendMode = BlendMode.MULTIPLY;
executeAction(app.charIDToTypeID('MrgV'), undefined, DialogModes.NO );
var fileName = outputFolder +"/"+win.panel0.name.text;
var saveFile = new File(fileName+".jpg");
SaveJPEG(saveFile, 12);
resize(170);
var saveFile = new File(fileName+"-m.jpg");
SaveJPEG(saveFile, 12);
resize(50);
var saveFile = new File(fileName+"-sm.jpg");
SaveJPEG(saveFile, 12);
resize(20);
var saveFile = new File(fileName+"-ico.jpg");
SaveJPEG(saveFile, 12);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
}

function Init(){
var Ini = new File("~/rememberFolder.ini");
if(!Ini.exists){
Ini.open("w");
Ini.writeln("");
Ini.close();
existFolder = '';
}else{
Ini.open("r");
existFolder = Ini.readln();
win.panel0.folder.text = Folder(existFolder).fsName;
outputFolder = Folder(existFolder);
Ini.close();
}}}

main();

function resize(width) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

var desc19 = new ActionDescriptor();
desc19.putUnitDouble( cTID('Wdth'), cTID('#Pxl'), width );
desc19.putBoolean( sTID('scaleStyles'), true );
desc19.putBoolean( cTID('CnsP'), true );
desc19.putEnumerated( cTID('Intr'), cTID('Intp'), cTID('Bcbc') );
executeAction( cTID('ImgS'), desc19, DialogModes.NO );
};

function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}