Python psd tools edit text

psd-tools¶

psd-tools is a Python package for working with Adobe Photoshop PSD files as described in specification.

Installation¶

Use pip to install the package:

In order to extract images from 32bit PSD files PIL/Pillow must be built with LITTLECMS or LITTLECMS2 support ( apt-get install liblcms2-2 or brew install little-cms2 )

Getting started¶

from psd_tools import PSDImage psd = PSDImage.open('example.psd') psd.composite().save('example.png') for layer in psd: print(layer) image = layer.composite() 

Check out the Usage documentation for more examples.

Features¶

  • Read and write of the low-level PSD/PSB file structure
  • Raw layer image export in NumPy and PIL format
  • Composition of basic pixel-based layers
  • Composition of fill layer effects
  • Vector masks
  • Editing of some layer attributes such as layer name
  • Blending modes except for dissolve
  • Drawing of bezier curves
  • Editing of layer structure, such as adding or removing a layer
  • Composition of adjustment layers
  • Composition of many layer effects
  • Font rendering
  • psd_tools
  • psd_tools.api.adjustments
  • psd_tools.api.effects
  • psd_tools.api.layers
  • psd_tools.api.mask
  • psd_tools.api.shape
  • psd_tools.api.smart_object
  • psd_tools.constants
  • psd_tools.psd
  • psd_tools.psd.base
  • psd_tools.psd.color_mode_data
  • psd_tools.psd.descriptor
  • psd_tools.psd.engine_data
  • psd_tools.psd.effects_layer
  • psd_tools.psd.filter_effects
  • psd_tools.psd.header
  • psd_tools.psd.image_data
  • psd_tools.psd.image_resources
  • psd_tools.psd.layer_and_mask
  • psd_tools.psd.linked_layer
  • psd_tools.psd.patterns
  • psd_tools.psd.tagged_blocks
  • psd_tools.psd.vector
  • psd_tools.terminology

Indices and tables¶

© Copyright 2019, Kota Yamaguchi Revision 4daac1b9 .

Versions latest stable Downloads On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.

Источник

Python – 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
Читайте также:  Графики в pyqt5 python

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?

Best Solution

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

Python – How to print colored text to the terminal

This somewhat depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here’s some Python code from the Blender build scripts:

class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKCYAN = '\033[96m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' 

To use code like this, you can do something like:

print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC) 
print(f"Warning: No active frommets remain. Continue?") 

This will work on unixes including OS X, Linux and Windows (provided you use ANSICON, or in Windows 10 provided you enable VT100 emulation). There are ANSI codes for setting the color, moving the cursor, and more.

If you are going to get complicated with this (and it sounds like you are if you are writing a game), you should look into the «curses» module, which handles a lot of the complicated parts of this for you. The Python Curses HowTO is a good introduction.

If you are not using extended ASCII (i.e., not on a PC), you are stuck with the ASCII characters below 127, and ‘#’ or ‘@’ is probably your best bet for a block. If you can ensure your terminal is using a IBM extended ASCII character set, you have many more options. Characters 176, 177, 178 and 219 are the «block characters».

Some modern text-based programs, such as «Dwarf Fortress», emulate text mode in a graphical mode, and use images of the classic PC font. You can find some of these bitmaps that you can use on the Dwarf Fortress Wiki see (user-made tilesets).

The Text Mode Demo Contest has more resources for doing graphics in text mode.

Extract layers from PSD with ImageMagick, preserving layout

I use this command line to do what are describing:

convert.exe .psd -set dispose Background -coalesce .png 

Источник

Оцените статью