Batch Resizing multiple sizes to multiple locations?

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

Patrick

Batch Resizing multiple sizes to multiple locations?

Post by Patrick »

fmphoto wrote:In what program do I start editing the script and how do I save it as a .jsx file? Like I said, I'm totally new and have no real idea of how to get started or what to do. Thanks.

Photoshop installs a program called Extendscript Toolkit that you can use for editing scripts. You can just paste what I posted into a text editor and save as whatever.jsx. To load it in Photoshop, you do file > automate > open script and point it to your jsx file.

Also, if you look in your photoshop folder, there are some PDF documents on scripting that are very helpful when you are starting out.

Patrick
xbytor

Batch Resizing multiple sizes to multiple locations?

Post by xbytor »

Mike Hale wrote:X, did you notice that he wants to resize an image 6 times and save each size in it's own folder?

I misread. Not enough sleep
Paul MR

Batch Resizing multiple sizes to multiple locations?

Post by Paul MR »

You might like to try this...
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var Name = doc.name.replace(/\.[^\.]+$/, '');
var Path = decodeURI(doc.path);
createNamedSnapshot("Snap 1");
doc.resizeImage(900, undefined, 300, ResampleMethod.BICUBIC);
var outFolder = Folder(Path +"/900x900");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+"-300.jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(900, undefined, 72, ResampleMethod.BICUBIC);
var saveFile = File(outFolder +"/"+Name+"-72.jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(825, undefined, 300, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/825x825");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+".jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(500, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/500x500");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+".jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(150, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/150x150");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+".jpg");
SaveJPEG(saveFile,8);
revertNamedSnapshot("Snap 1");
doc.resizeImage(120, undefined, 72, ResampleMethod.BICUBIC);
outFolder = Folder(Path +"/120x120");
if(!outFolder.exists) outFolder.create();
var saveFile = File(outFolder +"/"+Name+".jpg");
SaveJPEG(saveFile,8);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
}

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);
}

function createNamedSnapshot(name) {
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putClass( charIDToTypeID('SnpS') );
    desc.putReference( charIDToTypeID('null'), ref );
        var ref1 = new ActionReference();
        ref1.putProperty( charIDToTypeID('HstS'), charIDToTypeID('CrnH') );
    desc.putReference( charIDToTypeID('From'), ref1 );
    desc.putString( charIDToTypeID('Nm  '), name );
    desc.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('HstS'), charIDToTypeID('FllD') );
    executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
}

function revertNamedSnapshot(name) {
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putName( charIDToTypeID('SnpS'), name );
    desc.putReference( charIDToTypeID('null'), ref );
    executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
}
fmphoto

Batch Resizing multiple sizes to multiple locations?

Post by fmphoto »

Paul MR,

I will let you know how that script works today. Thank you very much.

Paul! That does what I want to! How can I tweak that script so that it puts each 900x900 image in a separate folder.

UPDATE: I figured this out by simply adding a -300 and a -72 to the 900x900 folder script. Thanks for helping me grasp how to do this.

How can i tweak this script so that it is resizing the images on their longest edge? I am having trouble with this part.
Paul MR

Batch Resizing multiple sizes to multiple locations?

Post by Paul MR »

You could use a function like this...
Code: Select allfitImage(1800,300); //pixels - resolution

function fitImage(newImgSize,res) {
   var doc = app.activeDocument;
   if (res == undefined) res = undefined;
      if (doc.width > doc.height) {
         doc.resizeImage(new UnitValue(newImgSize,'px'), undefined, res, ResampleMethod.BICUBIC);
         } else
      if (doc.width < doc.height) {
         doc.resizeImage(undefined, new UnitValue(newImgSize,'px'), res, ResampleMethod.BICUBIC);
         } else
      if (doc.width == doc.height) {
         doc.resizeImage(new UnitValue(newImgSize,'px'), new UnitValue(newImgSize,'px'), res, ResampleMethod.BICUBIC);
         }
};
fmphoto

Batch Resizing multiple sizes to multiple locations?

Post by fmphoto »

Paul MR, Thanks again

Somehow with a little more googling I was able to find the Script commands for if height is greater than width then.....and figured out what to do with a little tinkering.

So I now have a working script that outputs it to all the necessary sizes, and if we need more sizes I know how to add on as well.

So to Paul MR and anyone else here that chimed in to help, thank you very much! It is much appreciated.