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!

save as procedure


webbuilders

Member
Messages
12
Likes
0
I want to make an Action do the following .....

i have many jpg images with for example width 630 and height 430

I want to cut it at half 315x215 and save its image seperatly if i had image test.jpg
i want to have test1.jpg and test2.jpg

Is this possible with action ... because i tried and i have problem with saving .. i tried batch too but i failed... Have anyone done it to tell me what to do???

Thanks
 
Your maths are not correct as you are asking for a quarter not half? 315x215=quarter
I will assume you mean half and this will do a folder of files..
Code:
function main(){
var inputFolder = Folder.selectDialog("Select a folder of documents to process");
if(inputFolder == null) return;
var fileList = inputFolder.getFiles(/\.(jpg|tif|psd)$/i); 
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

for(var z in fileList){
	open(fileList[z]);
var doc = app.activeDocument;
try{
var leftFile = new File(decodeURI(activeDocument.fullName.fsName).slice(0,-4) + "1.jpg");  
}catch(e){alert("You need to save this document first");return;}
var rightFile = new File(decodeURI(activeDocument.fullName.fsName).slice(0,-4) + "2.jpg");  
doc.flatten();
var LB = app.activeDocument.activeLayer.bounds; 
var savedState = doc.activeHistoryState;
activeDocument.selection.select([[LB[0].value,LB[1].value], [(LB[2].value/2),LB[1].value], [(LB[2].value/2),LB[3].value], [LB[0].value, LB[3].value]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
SaveJPEG(leftFile,8);
doc.activeHistoryState = savedState;
activeDocument.selection.select([[LB[2].value/2,LB[1].value], [(LB[2].value),LB[1].value], [(LB[2].value),LB[3].value], [LB[2].value/2, LB[3].value]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
SaveJPEG(rightFile,8);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
	}
}
main();

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);
}
 
The best thing to do is to paste the code into ExtendScript Toolkit this can be found..

PC: C:\Program Files\Adobe\Adobe Utilities
MAC: <hard drive>/Applications/Utilities/Adobe Utilities
Then save the script in..

PC: C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts
MAC: <hard drive>/Applications/Adobe Photoshop CS#/ Presets/Scripts

If Photoshop was open, close and restart Photoshop so that it can pick up the new script.
You can then run the script by File - Scripts and choose the script.

It will then prompt for the folder to process.
 
Paul MR
you really seem to know your stuff, that coding business just blows me away Nice info
 
Can i make one more newbie question ...

1. I saw the script and i see the jpg quality ..
How can i tell to the script that i want quality 70 ?? I dont know jsx at all ...

2. Can i tell the script to create and save to an other folder ?

Thanks
 
Last edited:
I have now modified it so that it asks for an output folder, also change the output to Save For Web with a quality of 70.
Code:
#target photoshop
function main(){
//Amend quality to suit
var Quality = 70;
var inputFolder = Folder.selectDialog("Select a folder of documents to process");
var outputFolder = Folder.selectDialog("Select Destination Folder");
if(inputFolder == null) return;
if(outputFolder == null) return;
var fileList = inputFolder.getFiles(/\.(jpg|tif|psd)$/i); 
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

for(var z in fileList){
	open(fileList[z]);
var doc = app.activeDocument;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
try{
var leftFile = new File(outputFolder +"/"+Name + "1.jpg");  
}catch(e){alert("You need to save this document first");return;}
var rightFile = new File(outputFolder +"/"+Name + "2.jpg");  
doc.flatten();
var LB=[];
LB = app.activeDocument.activeLayer.bounds; 
var savedState = doc.activeHistoryState;
activeDocument.selection.select([[LB[0].value,LB[1].value], [(LB[2].value/2),LB[1].value], [(LB[2].value/2),LB[3].value], [LB[0].value, LB[3].value]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
SaveForWeb(leftFile,Quality);
doc.activeHistoryState = savedState;
activeDocument.selection.select([[LB[2].value/2,LB[1].value], [(LB[2].value),LB[1].value], [(LB[2].value),LB[3].value], [LB[2].value/2, LB[3].value]], SelectionType.REPLACE, 0, false);
executeAction( charIDToTypeID( "Crop" ), undefined, DialogModes.NO );
SaveForWeb(rightFile,Quality);
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);
}
 

Back
Top