Batch resizing rectangle to square

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

dikiz

Batch resizing rectangle to square

Post by dikiz »

Just great !
Works fine, I'm so grateful to you!
Cheers from France!
Ryan Ron

Batch resizing rectangle to square

Post by Ryan Ron »

Batch Image converting and editing is a feature that's not special in the photography field. When we want converting a lot of pictures format to others usable format as well as watermarked or resized also, then batch converter software be able to take care of it for us.
dikiz

Batch resizing rectangle to square

Post by dikiz »

Paul MR wrote:This should do the selected folder and all it's sub folders.
It is only looking for JPGs and it is using Bridge to check the file sizes.
The JPGs will be overwritten! so do a test first to make sure it works as required!

Code: Select all#target Photoshop
app.bringToFront();

main();
function main(){
var folders =[];
var topLevel = Folder.selectDialog("Please select top level folder");   
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var t in folders){
fileList = getFilesFromBridge(decodeURI(folders[t]));
for(var v in fileList){
    open(File( folders[t] + "/" + fileList[v]));
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var newSize = (doc.width+doc.height)/2;
doc.resizeImage(newSize, newSize,undefined, ResampleMethod.BICUBICSHARPER);
doc.save();
doc.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
    }
    }
}
function getFilesFromBridge( selectedFolder){
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = "var ftn = " + script.toSource() + "; ftn(" + selectedFolder.toSource() +");";
bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }
bt.onError = function( inBT ) { fileList = new Array(); }
bt.send(20);
bt.pump();
if ( undefined == fileList ) fileList = new Array();
return fileList;
}
function script(selectedFolder){
var fList=[];
app.document.thumbnail = Folder(selectedFolder);
var fileList1 = Folder(selectedFolder).getFiles('*.jpg','png');
for(var a in fileList1){
var Thumb = new Thumbnail(fileList1[a].fsName);
app.synchronousMode = true;
var Height = Thumb.core.quickMetadata.height;
var Width = Thumb.core.quickMetadata.width;
app.synchronousMode = false;
if(Height != Width) fList.push(decodeURI(Thumb.spec.name));
Thumb=null;
}
return fList.toSource();
}
function FindAllFolders( srcFolderStr, destArray) {
   var fileFolderArray = Folder( srcFolderStr ).getFiles();
   for ( var i = 0; i < fileFolderArray.length; i++ ) {
      var fileFoldObj = fileFolderArray;
      if ( fileFoldObj instanceof File ) {         
      } else {
         destArray.push( Folder(fileFoldObj) );
      FindAllFolders( fileFoldObj.toString(), destArray );
      }
   }
   return destArray;
}


For some reasons, the code is not working anymore
I have this message (translated from French) : "Error 2: fileList is not defined. Lign: 33"
I haven't changed anything to my config (and CS6)...
Someone has an idea Thanks
pfaffenbichler

Batch resizing rectangle to square

Post by pfaffenbichler »

Instead of an if-clause you could try using a try-clause like
Code: Select alltry {fileList} catch (e) {fileList = new Array};
dikiz

Batch resizing rectangle to square

Post by dikiz »

Where should I put your line? Thank you
dikiz

Batch resizing rectangle to square

Post by dikiz »

Actually I realised that the script was working when I was using CS 5.1; no longer works on CS 6.1.
pfaffenbichler

Batch resizing rectangle to square

Post by pfaffenbichler »

Where should I put your line?
How many if-clauses are part of the code?