Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing Photoshop PSD text layers programmatically

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?

like image 595
EvanK Avatar asked May 12 '09 02:05

EvanK


People also ask

How do I edit PSD text in Photoshop?

To edit text on a type layer, select the type layer in the Layers panel and select the Horizontal or Vertical Type tool in the Tools panel. Make a change to any of the settings in the options bar, such as font or text color. When you're finished editing, click the check mark in the options bar.

How can I edit text in a PSD file without Photoshop?

Gimp is the closest open-source alternative to Photoshop. The app looks quite similar to Photoshop in terms of layout. With Gimp, you can not only open a PSD file but also do basic edit just like you would do with Photoshop.


2 Answers

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=...).

like image 57
wr. Avatar answered Sep 23 '22 11:09

wr.


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.

like image 42
Cassie Meharry Avatar answered Sep 23 '22 11:09

Cassie Meharry