Follow us on Twitter!
Follow us on Facebook!
 

Go Back   Pixtus - Photography Forum, Photographers, Photo Tips > Photography Information > Post Processing Central


Today I learned Javascript in Photoshop

This is a discussion on Today I learned Javascript in Photoshop within the Post Processing Central forums, part of the Photography Information category; Wow, this is some powerful stuff. I guess I just eeked about $100 of value out of Photoshop that was ...

Reply
 
LinkBack Thread Tools Display Modes
  (#1) Old
Forum Master
 
dmcantrell's Avatar
 
Posts: 1,393
Join Date: Dec 2009
Location: Austin, Texas
Real First Name: David
Camera: Nikon D300
Can Others Edit My Photos: Yes
iTrader Rating: 7

Likes Received LIKES Received: 51
Likes Given LIKES Given: 36
Today I learned Javascript in Photoshop - 05-09-2010, 05:05 PM


Wow, this is some powerful stuff. I guess I just eeked about $100 of value out of Photoshop that was previously going unused.

---------------------------
3&3 Studios | Flickr | iStock | Facebook

Never waste the opportunities offered by a good crisis -Niccolò Machiavelli
Reply With Quote
Sponsored Links

Premium Members do not see Google advertisements. SIGN UP today and help support our community.
  (#2) Old
Forum Regular
 
RKEnnis's Avatar
 
Posts: 966
Join Date: Mar 2006
Location: San Antonio, Texas
Real First Name: Randy
Camera: Nikon
Can Others Edit My Photos: Yes
iTrader Rating: 1

Likes Received LIKES Received: 4
Likes Given LIKES Given: 3
05-09-2010, 08:20 PM


Sweet! You were automating something, I take it?

JavaScript may be the best scripting language ever...

---------------------------
Randy
www.txphotoblog.com
Reply With Quote
  (#3) Old
Forum Master
 
dmcantrell's Avatar
 
Posts: 1,393
Join Date: Dec 2009
Location: Austin, Texas
Real First Name: David
Camera: Nikon D300
Can Others Edit My Photos: Yes
iTrader Rating: 7

Likes Received LIKES Received: 51
Likes Given LIKES Given: 36
05-09-2010, 08:50 PM


Yes I automated some task that I found myself doing over and over.

Like resizing the image down to 800 longest edge at 300dpi, and saving jpeg quality 9 with a <image_name)_c1_800.jpg extension in a particular folder.

---------------------------
3&3 Studios | Flickr | iStock | Facebook

Never waste the opportunities offered by a good crisis -Niccolò Machiavelli
Reply With Quote
  (#4) Old
rebmeM muimerP
 
Jake's Avatar
 
Posts: 6,225
Join Date: Jan 2005
Location: Watauga(DFW), Texas
Real First Name: Jake
Camera: Canon 5D2
Can Others Edit My Photos: Yes
iTrader Rating: 14

Likes Received LIKES Received: 352
Likes Given LIKES Given: 275
05-10-2010, 09:17 AM


Cool, now explain everything you learned in a way a 5yr old could understand.
I'm ready and taking notes.......

---------------------------
Check out the NEW Pixtus Photography Cheat Sheet!
Reply With Quote
  (#5) Old
Forum Master
 
dmcantrell's Avatar
 
Posts: 1,393
Join Date: Dec 2009
Location: Austin, Texas
Real First Name: David
Camera: Nikon D300
Can Others Edit My Photos: Yes
iTrader Rating: 7

Likes Received LIKES Received: 51
Likes Given LIKES Given: 36
05-10-2010, 09:29 AM


Sure thing, I will post the actual code later on tonight when I get home.

I made two scripts to do two specific things that I do -alot-. I seem to spend quite a bit of time doing these repetitive tasks and click click clicking in the dialog boxes.

1) Resize images to 800px / 300dpi.
----
I do this all the time. I save a full-sized version in .psd format with layers, then resize down to 800px / 300dpi for web-posting. The problem is that the 800px is the long edge, so the user needs to know which of the fields in the resize dialog box to change the 800. Also, the aspect ratio needs to be considered. My script will compare the height and width to determine which is larger, calculate the aspect ratio, then call the image resizer with the results of the calculations. The result is a 300dpi image with the same aspect ratio as the original, sized down so that the longest edge is 800px after one click.

2) Save As JPEG (quality 9) with my own naming convention
----
This is another task I find myself doing a lot. Change mode to 8-bit, save-as jpeg, change the file name, choose 9 quality, click click click. My script will determine if the image is in 8 or 16-bit, change it to 8-bit, call the 'Save As' dialog, change the filename to <original_name>c1_800.jpg (my naming convention), and save the file as JPEG with quality 9 with one click.

I wrote the scripts by hand in a text editor (VIM), and saved them with a .jsx file extension. I put them in the /Scripts folder (see the Photoshop documentation) so that they can be accessed via the File-->Scripts--> menu. Then, I made some new actions that executed the scripts so that I could have a one-click solution without having to go two menus deep to get to them.

---------------------------
3&3 Studios | Flickr | iStock | Facebook

Never waste the opportunities offered by a good crisis -Niccolò Machiavelli
Reply With Quote
  (#6) Old
Forum Master
 
dmcantrell's Avatar
 
Posts: 1,393
Join Date: Dec 2009
Location: Austin, Texas
Real First Name: David
Camera: Nikon D300
Can Others Edit My Photos: Yes
iTrader Rating: 7

Likes Received LIKES Received: 51
Likes Given LIKES Given: 36
05-11-2010, 05:27 PM


-------------- resize_to_800.jsx -----------------
Code:
// the active document
var AD=activeDocument;

if (AD.width.value > AD.height.value) {
  // process width
  var currentAspectRatio = AD.width.value / AD.height.value;
  alert (currentAspectRatio);
  var newHeight = 800 / currentAspectRatio;
  var newWidth = 800;
  AD.resizeImage (newWidth, newHeight, 300, ResampleMethod.BILINEAR);
} 
else {
  // process height
  var currentAspectRatio = AD.height.value / AD.width.value;
  alert (currentAspectRatio);
  var newHeight = 800;
  var newWidth = 800 / currentAspectRatio;
  AD.resizeImage (newWidth, newHeight, 300, ResampleMethod.BILINEAR);
}
----------------- save_as_jpg_9.jsx --------------------
Code:
// the active document
var AD=activeDocument;

// set to 8-bit depth for saving
var currentBitsPerChannel = AD.bitsPerChannel;
AD.bitsPerChannel = BitsPerChannelType.EIGHT ;

// If any documentes are open
if (app.documents.length >=1) {
  // create a variable to get the current document name
  myDoc = app.activeDocument.name;
}
  else {
  sampleDoc = "There are no documents open.";
}

// add the desired file name extension
var newFileName = myDoc.slice(0,-4) + "_c1_800"

alert (newFileName)

saveFile = new File(decodeURI(app.activeDocument.path)+'/'+newFileName+'.jpg')
saveOptions = new JPEGSaveOptions()
saveOptions.embedColorProfile = true
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE
saveOptions.matte = MatteType.NONE
saveOptions.quality = 9
AD.saveAs(saveFile, saveOptions, true, Extension.LOWERCASE)

AD.bitsPerChannel = currentBitsPerChannel;
I put both of these files into C:/Program Files/Adobe/Adobe Photoshop CS4/Presets/Scripts

---------------------------
3&3 Studios | Flickr | iStock | Facebook

Never waste the opportunities offered by a good crisis -Niccolò Machiavelli

Last edited by dmcantrell; 05-11-2010 at 06:02 PM..
Reply With Quote
  (#7) Old
Forum Regular
 
RKEnnis's Avatar
 
Posts: 966
Join Date: Mar 2006
Location: San Antonio, Texas
Real First Name: Randy
Camera: Nikon
Can Others Edit My Photos: Yes
iTrader Rating: 1

Likes Received LIKES Received: 4
Likes Given LIKES Given: 3
05-11-2010, 06:16 PM


Thanks for posting the code!

Whats up those alerts - don't you know your supposed to remove them from all production code? hehehe j/k!

Seriously, you've inspired me to get back into automating PS. There's some stuff I've wanted to do, but I've been too lazy. Plus I've taken too long a break from coding...

---------------------------
Randy
www.txphotoblog.com
Reply With Quote
  (#8) Old
Forum Master
 
dmcantrell's Avatar
 
Posts: 1,393
Join Date: Dec 2009
Location: Austin, Texas
Real First Name: David
Camera: Nikon D300
Can Others Edit My Photos: Yes
iTrader Rating: 7

Likes Received LIKES Received: 51
Likes Given LIKES Given: 36
05-11-2010, 06:25 PM


Quote:
Originally Posted by RKEnnis View Post
Thanks for posting the code!
no problem!

Quote:
Whats up those alerts - don't you know your supposed to remove them from all production code? hehehe j/k!

---------------------------
3&3 Studios | Flickr | iStock | Facebook

Never waste the opportunities offered by a good crisis -Niccolò Machiavelli
Reply With Quote
Reply

Tags
javascript, learned, photoshop, today

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Visit Our Sponsors
 

Google Sponsors

Premium Members do not see Google advertisements. SIGN UP today and help support our community.

Copyright ©2004 - 2011, Abel Longoria - www.Pixtus.com
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.