November 04, 2007

Recursive export to Web in Photoshop CS3

JavaScript | Photo

I use Adobe Lightroom to organize my photographs, both digital ones as well as the scanned slide films I take. Lightroom is working great for me and I've written about my disappointment with Apple Aperture in a previous entry.

Yesterday I was looking for a way to take a subset of the pictures I have and convert them to JPG. I want to use the JPGs on a small Mac Mini to make presentation in FrontRow using a newly acquired Canon SX7 digital projector (more on this in a later entry).

Unfortunately Adobe Lightroom does not offer such a functionality. You can export all the pictures in a directory to JPG, but there's no way to take a directory, and recursively export all the pictures within it to JPG while maintaining the directory structure they are in.

I could have written a small shell script to do this, but I have a mixture of TIFF, JPG and RAW images that had to be processed. I wanted to get the image processing capabilities from Lightroom or Photoshop, instead of using dcraw. Adobe Lightroom doesn't have a way to script it, so I looked at Photoshop CS3 to do it.

Photoshop can be scripted in JavaScript, in addition to AppleScript. I came up with a small script that does the conversion.

To use, download the script, install it in /Applications/Adobe Photoshop CS3/Presets/Scripts and restart Photoshop CS3.

After restart, the script is available under File -> Scripts. When you select it, the script will ask the source directory containing the images, and the destination directory where the JPG images should be placed. The script has been tested in Photoshop CS3 running on MacOS X 10.4.10. It seems to be able to process TIFF files produced by my scanner, CR2 RAW files from my 5D and the older 20D, as well as JPGs from various digital point-and-shoot cameras.

If you stop the script, the next time you restart it on the same source and destination directories, it will not process the files that have already been processed.

Note that if you process a lot of files, Photoshop ends up using a lot of the disk space on your scratch disk. I could not figure out why this happens. Quitting Photoshop seems to reclaim the scratch disk space.

The script is public domain, feel free to use and modify it as you wish. If you do end up using it and fix various bugs, please let me know so I can incorporate them in my script.

Posted by ovidiu at 04:47 PM | Comments (0) |

February 26, 2004

JavaScript introspection

Early morning in the Valley (Mt Hamilton, California)

JavaScript is a very loose language, but has some interesting properties. Some of them are not obvious or are quite weird.

The language uses prototype inheritance rather than the usual class inheritance from languages like Java, C++ or Python. To declare a class, you simply define a constructor function, which is really a normal function:

function MyClass() {}

The constructor defines a new property in the global space, named MyClass. The value associated with it is a function object that does nothing in our case.

To create an instance of MyClass you simply call the constructor:

var obj = new MyClass();

The new operator will create a new JavaScriptObject and invoke the function associated with the MyClass name, passing to it as invisible argument the newly created Object instance. Inside the "constructor" function, the code can use the special this property to refer to the instance.

The following code snippet:

function MyClass() {
this.ivar = 1;

creates a new property named ivar associated with the receiving Object instance.

In JavaScript all objects act as hash tables. The keys in the hash tables are the names of the "instance variables" or "properties". With the latter definition of MyClass() and the obj definition above, the following two expressions return the same object: obj.ivar and obj["ivar"].

If an instance variable is not declared and you refer to it using the this["name-of-variable"] you obtain the null value. This is nice since you can now verify if an instance variable is defined or not.

In JavaScript classes are just properties of the global scope object. The global scope is accessible through the this keyword. To obtain the MyClass object for example, you can do:


You can also refer to the top-level obj variable with the expression:


You can iterate over all the variables and classes defined in the global scope by doing:

for (i in this) print(i);

Quite nifty, huh? On the right is the JavaScript bible I use. The information above is not in it though...

Posted by ovidiu at 08:24 PM |
Cool stuff
  Arduino TinyWebServer: part 3 and part 2
More from me
Picture gallery
Copyright © 2002-2016 Ovidiu Predescu.