Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to take original image and save out different sizes.

Guest
Feb 11, 2009 Feb 11, 2009
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
TOPICS
Actions and scripting
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
New Here ,
Feb 12, 2009 Feb 12, 2009
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2009 Feb 12, 2009
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 12, 2009 Feb 12, 2009
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...































































































Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2009 Feb 12, 2009
Actually I would consider You one of them, Paul.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 12, 2009 Feb 12, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 12, 2009 Feb 12, 2009
No payment required, I'am retired and do this for fun. Hope it works ok for you.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 12, 2009 Feb 12, 2009
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 12, 2009 Feb 12, 2009
I'm not retired; I do this for kharma.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2009 Feb 12, 2009
Now that makes me curious  have You all struck it rich and (semi-)retired early or are You actually venerable old-age-pensioneers?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 12, 2009 Feb 12, 2009
At sixtynine you could class me as an old age pensioner.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 12, 2009 Feb 12, 2009
At 40 am I too old to learn, strike it rich and retire with a pocket full of beer vouchers?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 12, 2009 Feb 12, 2009
Hi Paul,

I ran the script and it is getting stuck on line 137 SaveJPEG - error SaveJPEG is not a function.

J
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 12, 2009 Feb 12, 2009
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...































































































Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 12, 2009 Feb 12, 2009
LATEST
😄 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines