0
Script to take original image and save out different sizes.

/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/td-p/1097780
Feb 11, 2009
Feb 11, 2009
Copy link to clipboard
Copied
Mac/PC Javascript Photoshop CS3
Here is a request I got from another client and I think it should be doable with Photoshop scripting but just need to know if it is doable (im pretty sure it is). Also I am willing to commission this out to someone if interested.
Files to start with are style#.jpg (i.e. RE1803.jpg)
They are large jpegs with various heights and widths
They want to export these jpegs in 3 other sizes 600X600 (light), 340X340 (details), 135X135 (listing)
What needs to happen is a folder needs to be created with the name of the style number (RE1803) then the 3 new jpegs need to be saved in the folder so RE1803.jpg is saved as light.jpg (for 600X600), details.jpg (for 340X340) and listing.jpg (for 135X135) in a folder called RE1803.
Since the sizes of the original jpegs are all different I guess we would need to find the longest side and then scale it down to 600 pixels then add canvas to make it a square 600X600. Then it will be easy to export the next as 340X340 and then 135X135.
Also it would be good if the script could be run both one at a time and maybe also on a whole folder of images if possible.
Would be great if I can get this done asap.
Thanks in advance!
Jason
Here is a request I got from another client and I think it should be doable with Photoshop scripting but just need to know if it is doable (im pretty sure it is). Also I am willing to commission this out to someone if interested.
Files to start with are style#.jpg (i.e. RE1803.jpg)
They are large jpegs with various heights and widths
They want to export these jpegs in 3 other sizes 600X600 (light), 340X340 (details), 135X135 (listing)
What needs to happen is a folder needs to be created with the name of the style number (RE1803) then the 3 new jpegs need to be saved in the folder so RE1803.jpg is saved as light.jpg (for 600X600), details.jpg (for 340X340) and listing.jpg (for 135X135) in a folder called RE1803.
Since the sizes of the original jpegs are all different I guess we would need to find the longest side and then scale it down to 600 pixels then add canvas to make it a square 600X600. Then it will be easy to export the next as 340X340 and then 135X135.
Also it would be good if the script could be run both one at a time and maybe also on a whole folder of images if possible.
Would be great if I can get this done asap.
Thanks in advance!
Jason
TOPICS
Actions and scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explore related tutorials & articles
New Here
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097781#M447700
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
From an AppleScript (mac) point of view yes your request is very "doable" Im a total beginner with JavaScript but I can't think of any reason why it would not be the same. If you want to run on either OS then a JavaScript solution is what you want.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097782#M447701
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
All the necessary steps appear scriptable in JavaScript too.
There are a couple of pros frequenting this forum who, Im certain, could provide such a Script easily and speedily.
There are a couple of pros frequenting this forum who, Im certain, could provide such a Script easily and speedily.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097783#M447702
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
Whilst we are waiting for a pro this might fit the bill....
function main(){
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,610,260],"+
"panel0:Panel{bounds:[10,10,500,140] , text:'Save Styles' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"file:RadioButton{bounds:[40,20,161,41] , text:'Single File' },"+
"folder:RadioButton{bounds:[170,20,371,41] , text:'Folder of Files' },"+
"Path:EditText{bounds:[10,50,370,70] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse:Button{bounds:[380,50,480,70] , text:'Browse' },"+
"button1:Button{bounds:[10,90,240,111] , text:'Ok' },"+
"button2:Button{bounds:[250,90,480,111] , text:'Cancel' }}};";
var win = new Window(dlg,"Style Sizer");
win.panel0.file.value=true;
win.panel0.Path.enabled=false;
win.center();
win.panel0.file.onClick = function(){
win.panel0.Path.text = '';
}
win.panel0.folder.onClick = function(){
win.panel0.Path.text = '';
}
win.panel0.Browse.onClick = function() {
if(win.panel0.file.value){
var selectedFile = File.openDialog("Please select JPG file.","JPG File:*.jpg");
if(selectedFile != null){
win.panel0.Path.text = decodeURI(selectedFile.fsName);
FILEPATH = new File(decodeURI(selectedFile.fsName));
}}
if(win.panel0.folder.value){
var selectedFolder = Folder.selectDialog( "Please select folder");
if(selectedFolder != null){
win.panel0.Path.text = decodeURI(selectedFolder.fsName);
FILEPATH = new Folder(decodeURI(selectedFolder.fsName));;
}}
}
var done = false;
while (!done) {
var x = win.show();
if (x == 0 || x == 2) {
win.canceled = true;
done = true;
} else if (x == 1) {
done = true;
var result = valiDate();
if(result != true) {
alert(result);
return;
}else
{
processPics(FILEPATH);
}
}
}
function valiDate(){
if(win.panel0.Path.text == '') return "File/Folder not selected!";
return true;
}
function processPics(){
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
resetColours();
if(win.panel0.file.value){
var file= open(FILEPATH);
var dirStyle =decodeURI(file.path)+"/"+ file.name.slice(0,-4);
CreateDirectory(dirStyle);
fitImage(600);
app.activeDocument.resizeCanvas(600, 600, AnchorPosition.MIDDLECENTER);
SaveJPEG(new File(dirStyle+"/"+"light.jpg"), 80 );
fitImage(340);
SaveJPEG(new File(dirStyle+"/"+"details.jpg"), 80 );
fitImage(135);
SaveJPEG(new File(dirStyle+"/"+"listing.jpg"), 80 );
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}else{
var fileList = FILEPATH.getFiles("*.jpg");
for(var a= 0;a<fileList.length;a++){
var file= open(fileList);
var dirStyle =decodeURI(file.path)+"/"+ file.name.slice(0,-4);
CreateDirectory(dirStyle);
fitI...
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097784#M447703
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
Actually I would consider You one of them, Paul.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097785#M447704
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
wow excellent! I will give this a whirl and get back to you this afternoon. Thanks all for the input.
Btw Paul I will most definitely pay you for your time for this.
Thank you very much
Jason
Btw Paul I will most definitely pay you for your time for this.
Thank you very much
Jason
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097786#M447705
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
No payment required, I'am retired and do this for fun. Hope it works ok for you.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097787#M447706
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
Paul_R@adobeforums.com wrote:
> I'am retired and do this for fun.
I'm (semi) retired and do this for beer money and Raptor drives :)
-X
> I'am retired and do this for fun.
I'm (semi) retired and do this for beer money and Raptor drives :)
-X
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097788#M447707
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
I'm not retired; I do this for kharma.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097789#M447708
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
Now that makes me curious have You all struck it rich and (semi-)retired early or are You actually venerable old-age-pensioneers?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097790#M447709
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
At sixtynine you could class me as an old age pensioner.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097791#M447710
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
At 40 am I too old to learn, strike it rich and retire with a pocket full of beer vouchers?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097792#M447711
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
Hi Paul,
I ran the script and it is getting stuck on line 137 SaveJPEG - error SaveJPEG is not a function.
J
I ran the script and it is getting stuck on line 137 SaveJPEG - error SaveJPEG is not a function.
J
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097793#M447712
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
Very sorry, I am going senile. I had it saving as a normal JPG but decided to change it to Save For Web and didn't change the single file saves. This should work now....
function main(){
var dlg =
"dialog{text:'Script Interface',bounds:[100,100,610,260],"+
"panel0:Panel{bounds:[10,10,500,140] , text:'Save Styles' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"file:RadioButton{bounds:[40,20,161,41] , text:'Single File' },"+
"folder:RadioButton{bounds:[170,20,371,41] , text:'Folder of Files' },"+
"Path:EditText{bounds:[10,50,370,70] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse:Button{bounds:[380,50,480,70] , text:'Browse' },"+
"button1:Button{bounds:[10,90,240,111] , text:'Ok' },"+
"button2:Button{bounds:[250,90,480,111] , text:'Cancel' }}};";
var win = new Window(dlg,"Style Sizer");
win.panel0.file.value=true;
win.panel0.Path.enabled=false;
win.center();
win.panel0.file.onClick = function(){
win.panel0.Path.text = '';
}
win.panel0.folder.onClick = function(){
win.panel0.Path.text = '';
}
win.panel0.Browse.onClick = function() {
if(win.panel0.file.value){
var selectedFile = File.openDialog("Please select JPG file.","JPG File:*.jpg");
if(selectedFile != null){
win.panel0.Path.text = decodeURI(selectedFile.fsName);
FILEPATH = new File(decodeURI(selectedFile.fsName));
}}
if(win.panel0.folder.value){
var selectedFolder = Folder.selectDialog( "Please select folder");
if(selectedFolder != null){
win.panel0.Path.text = decodeURI(selectedFolder.fsName);
FILEPATH = new Folder(decodeURI(selectedFolder.fsName));;
}}
}
var done = false;
while (!done) {
var x = win.show();
if (x == 0 || x == 2) {
win.canceled = true;
done = true;
} else if (x == 1) {
done = true;
var result = valiDate();
if(result != true) {
alert(result);
return;
}else
{
processPics(FILEPATH);
}
}
}
function valiDate(){
if(win.panel0.Path.text == '') return "File/Folder not selected!";
return true;
}
function processPics(){
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
resetColours();
if(win.panel0.file.value){
var file= open(FILEPATH);
var dirStyle =decodeURI(file.path)+"/"+ file.name.slice(0,-4);
CreateDirectory(dirStyle);
fitImage(600);
app.activeDocument.resizeCanvas(600, 600, AnchorPosition.MIDDLECENTER);
SaveForWeb(new File(dirStyle+"/"+"light.jpg"), 80 );
fitImage(340);
SaveForWeb(new File(dirStyle+"/"+"details.jpg"), 80 );
fitImage(135);
SaveForWeb(new File(dirStyle+"/"+"listing.jpg"), 80 );
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}else{
var fileList = FILEPATH.getFiles("*.jpg");
for(var a= 0;a<fileList.length;a++){
var file= open(fileList);
var dirStyle =decodeURI(file.path)+"/"+ file.name.slice(0,-4);
CreateDirectory(dirStyle);
fitI...
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/photoshop-ecosystem-discussions/script-to-take-original-image-and-save-out-different-sizes/m-p/1097794#M447713
Feb 12, 2009
Feb 12, 2009
Copy link to clipboard
Copied
😄 Thanks so much Paul it seems to work!
J
p.s. I know you said Payment not required but if you change your mind id like to at least give you some $ for the super fast help. My email is in my User Profile.
J
p.s. I know you said Payment not required but if you change your mind id like to at least give you some $ for the super fast help. My email is in my User Profile.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

