Tue, 16 Jan 2007

Javascript in Photoshop

— SjG @ 9:21 pm

Ah, it was such a happy day that a Photoshop junkie and programmer geek discovered that Photoshop could be scripted with a Real Object-Oriented Language, like Javascript!

And yet, as time goes on, this happiness is mitigated. Egregious bugs (such as the failure of Selection.bounds) pop up, requiring internet searches to get the workaround. Then, there are unexpected things, where the document units are not honored for selection translations.

Even worse, it dawns on the programmer that many useful functions are missing — functions that seem like natural features for scripting Photoshop — like, say, getting the RGB value of an arbitrary pixel from an RGB document, or getting the transparency of said pixel, or, even, say, changing that value. Of course, there are workarounds for all of these functions (e.g.,this ). But why should I need fifteen extra lines of code?

Then, there are errors that are in my code. I find that aliasing is a big problem when I’m creating virtual triangles and then getting the pixels from within them. For example, my script for simplifying the creation of images like this:


has enough slop in the aliasing combines with the rotations and translations to yield problems like this:


So maybe it’s time for me to start implementing this kind of thing in a vector-based program. I’ve played with the demo of Intaglio, and it looks good. And it’s scriptable too, albeit only using AppleScript, which I’ll have to learn.

3 responses to “Javascript in Photoshop”

  1. Simon F. says:

    Hey Samuel

    Have you thought of writing JS to do drawing in a ? If course, you won’t get vector art that you can save, but at least you’ll get pretties to put on a web page.

    An alternative might be to look at doing this in directly in Core Graphics via Cocoa, perhaps via python bindings.

  2. Simon F. says:

    Hrm, that last comment should read “… do drawing in a <canvas>”

  3. Samuel says:

    I’ve been meaning to learn to do some Cocoa programming for a while now. It’s just a matter of finding the time. It seems like it wouldn’t be hard to output postscript.

    Doing it using a canvas is an interesting idea. I’ll have to look into that!

    I once wrote a bunch of this stuff in Java back in the late 90s, but I seem to have misplaced all my source files.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.