views:

1779

answers:

5

I have a multi-layered PSD, with one specific layer being non-rasterized text. I'm trying to figure out a way I can, from a bash/perl/python/whatever-else program:

  1. load the PSD
  2. edit the text in said layer
  3. flatten all layers in the image
  4. save as a web-friendly format like PNG or JPG

I immediately thought of ImageMagick, but I don't think I can edit the text layer through IM. If I can accomplish the first two steps some other programmatic way, I can always use ImageMagick to perform the last two steps.

After a couple of hours of googling and searching CPAN and PyPI, I still have found nothing promising. Does anyone have advice or ideas on the subject?

+1  A: 

If you're going to automate Photoshop, you pretty much have to use Photoshop's own scripting systems. I don't think there's a way around that.

Looking at the problem a different way, can you export from Photoshop to some other format which supports layers, like PNG, which is editable by ImageMagick?

AmbroseChapel
+3  A: 

The only way I can think of to automate the changing of text inside of a PSD would be to use a regex based substitution.

  1. Create a very simple picture in Photoshop, perhaps a white background and a text layer, with the text being a known length.
  2. Search the file for your text, and with a hex editor, search nearby for the length of the text (which may or may not be part of the file format).
  3. Try changing the text, first to a string of the same length, then to something shorter/longer.
  4. Open in Photoshop after each change to see if the file is corrupt.

This method, if viable, will only work if the layer in question contains a known string, which can be substituted for your other value. Note that I have no idea whether this will work, as I don't have Photoshop on this computer to try this method out. Perhaps you can make it work?

As for converting to png, I am at a loss. If the replacing script is in Python, you may be able to do it with the Python Imaging Library (PIL, which seems to support it), but otherwise you may just have to open Photoshop to do the conversion. Which means that it probably wouldn't be worth it to change the text pragmatically in the first place.

bluejeansummer
Good idea with the hex editing, but unfortunately it doesn't seem to change the text in the layer at all (and if I replace it with a string of different length, it corrupts the PSD file).
EvanK
+3  A: 

If you don't like to use the officially supported AppleScript, JavaScript, or VBScript, then there is also the possibility to do it in Python. This is explained in the article Photoshop scripting with Python, which relies on Photoshop's COM interface.

I have not tried it, so in case it does not work for you: If your text is preserved after conversion to SVG then you can simply replace it by whatever tool you like. Afterwards, convert it to PNG (eg. by inkscape --export-png=...).

wr
I think I'm going to go this route. It seems like the most consistent option aside from PS' built-in scripting (which if I'm not mistaken has to be kicked off manually from within Photoshop)
EvanK
+3  A: 

Have you considered opening and editing the image in The GIMP? It has very good PSD support, and can be scripted in several languages.

Which one you use depends in part on your platform, the Perl interface didn't work on Windows the last I knew. I believe Scheme is supported in all ports.

+2  A: 

You can use Photoshop itself to do this with OLE. You will need to install Photoshop, of course. Win32::OLE in Perl or similar module in Python. See http://www.adobe.com/devnet/photoshop/pdfs/PhotoshopScriptingGuide.pdf

Alexandr Ciornii