Я написал скрипт Photoshop CS5 на javascript для изменения размера и сохранения открытых изображений на основе формулы @ vache.Надеюсь, кто-то найдет это полезным:
var outputFolder = Folder.selectDialog("Select a folder for the output files")
if(outputFolder != null) {
var startRulerUnits = app.preferences.rulerUnits
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop CS5 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.displayDialogs = DialogModes.NO
do {
var totalWidth = parseInt( prompt("How wide do they need to fit into?", 844) );
}
while(totalWidth <= 0 || isNaN(totalWidth));
var DL = documents.length;
var totalArea = 0;
for(a=0;a<DL;a++){
var cur = documents[a];
totalArea += cur.width / cur.height;
}
var newHeight = totalWidth / totalArea;
for(a=1;a<=DL;a++){
activeDocument = documents[a-1];
var AD=activeDocument;
// bring to front
app.activeDocument = AD;
AD.changeMode(ChangeMode.RGB);
var imgName= AD.name.toLowerCase();
imgName = imgName.substr(0, imgName.length -4);
AD.flatten();
AD.resizeImage(null,UnitValue(newHeight,"px"),null,ResampleMethod.BICUBIC);
//AD.resizeImage(UnitValue(newWidth,"px"),null,null,ResampleMethod.BICUBIC);
saveForWeb(outputFolder, imgName, AD);
}
// Close all the open documents
while (app.documents.length) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)
}
// Reset the application preferences
app.preferences.rulerUnits = startRulerUnits;
app.displayDialogs = startDisplayDialogs;
}
function saveForWeb(outputFolderStr, filename, AD)
{
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.JPEG;
opts.quality = 80;
if (filename.length > 27) {
file = new File(outputFolderStr + "/temp.jpg");
AD.exportDocument(file, ExportType.SAVEFORWEB, opts);
file.rename(filename + ".jpg");
}
else {
file = new File(outputFolderStr + "/" + filename + ".jpg");
AD.exportDocument(file, ExportType.SAVEFORWEB, opts);
}
}