What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Help - Batch splitting images in 2 with arbitrary sizes


Ying

New Member
Messages
2
Likes
0
Hello all!
I have a pretty difficult problem I haven't been able to solve using photoshop, but I'm sure it's because of my own ineptitude, not because the program can't do it. I was hoping someone knew enough to help me with it.

Here it goes:

I have a folder with 100+ images each of them wider than 512 pixels.
All the images have different sizes.
I need to split each image in two halves. The first half of 512, the second of the rest of image size.

So, if I had a image that's 712 x 20, I'd need image_1 of 512x20 and image_2 of 200x20.

Is there any way of doing this using Photoshop actions? Because otherwise I'm facing hours of very tedious work.
Any help will be greatly appreciated. Thank you very much! <3
 
Copy and paste the following code into ExtendScript (this gets installed with Photoshop) and run the script.
It will prompt for the folder of files to be processed. (I am guessing they are JPG)
The files will be split and put into anew folder called Processed off the selected folder.

Code:
#target photoshop
app.bringToFront();
function main(){
var inputFolder= Folder.selectDialog ("Please select folder to process");
if(inputFolder == null) return;
var fileList = inputFolder.getFiles("*.jpg");
var outFolder = Folder(inputFolder +"/Processed");
if(!outFolder.exists) outFolder.create();
for(var z in fileList){
    open(fileList[z]);
var doc = activeDocument;
var Name = decodeURI(fileList[z].name.replace(/\.[^\.]+$/, ''));
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var LB=[];
LB[0] = 0; 
LB[1] = 0;
LB[2] = 512;
LB[3] = doc.height.value;
doc.selection.select([[LB[0],LB[1]], [LB[2],LB[1]], [LB[2],LB[3]], [LB[0], LB[3]]], SelectionType.REPLACE, 0, false);
var savedState = doc.activeHistoryState;
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
saveFile= File(outFolder + "/" + Name + "-512.jpg");
SaveForWeb(saveFile,80);
doc.activeHistoryState = savedState;
doc.selection.invert();
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
saveFile= File(outFolder + "/" + Name + "-rest.jpg");
SaveForWeb(saveFile,80);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
}
}
main();
function SaveForWeb(saveFile,jpegQuality) {
var sfwOptions = new ExportOptionsSaveForWeb(); 
   sfwOptions.format = SaveDocumentType.JPEG; 
   sfwOptions.includeProfile = false; 
   sfwOptions.interlaced = 0; 
   sfwOptions.optimized = true; 
   sfwOptions.quality = jpegQuality; //0-100 
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}
 
That worked wonderfully! They where png, but making a few tweaks fixed that.

You just saved me hours of work. Thank you again :D
 

Back
Top