Just great !
Works fine, I'm so grateful to you!
Cheers from France!
Batch resizing rectangle to square
Batch resizing rectangle to square
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.
Batch resizing rectangle to square
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
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
Batch resizing rectangle to square
Instead of an if-clause you could try using a try-clause like
Code: Select alltry {fileList} catch (e) {fileList = new Array};
Code: Select alltry {fileList} catch (e) {fileList = new Array};
Batch resizing rectangle to square
Actually I realised that the script was working when I was using CS 5.1; no longer works on CS 6.1.
Batch resizing rectangle to square
Where should I put your line?
How many if-clauses are part of the code?
How many if-clauses are part of the code?