photoshop.protocol

class photoshop.protocol.ContentType

Message content type.

CANCEL_COMMAND = 8
DATA = 5
ERROR_STRING = 1
EVENT_STATUS = 9
FILE_STREAM = 7
ILLEGAL = 0
IMAGE = 3
KEEP_ALIVE = 6
PROFILE = 4
SCRIPT = 2
SCRIPT_SHARED = 10
class photoshop.protocol.Pixmap(width, height, row_bytes, color_mode, channels, bits, data)

Pixmap representing an uncompressed pixels, ARGB, row-major order.

Variables:
  • width – width of the image.
  • height – height of the image.
  • row_bytes – bytes per row.
  • color_mode – color mode of the image.
  • channels – number of channels.
  • bits – bits per pixel.
  • data – raw data bytes.
dump()

Dump Pixmap to bytes.

classmethod parse(data)

Parse Pixmap from data.

topil()

Convert to PIL Image.

class photoshop.protocol.Protocol(password)

Photoshop protocol.

VERSION = 1
receive(socket)

Receives data from Photoshop.

Parameters:socket – socket to receive data.
Returns:dict of the following fields.
  • status: execution status, 0 when success, otherwise error.
  • protocol: protocol version, equal to 1.
  • transaction: transaction id.
  • content_type: data type. See ContentType.
  • body: body of the response data, dict for IMAGE type, otherwise bytes.

Example:

{
    'status': 0,
    'protocol': 1,
    'transaction': 0,
    'content_type': ContentType.SCRIPT,
    'body': b'[ActionDescriptor]'
}
Raises:AssertionError – if response format is invalid.
send(socket, content_type, data, transaction=0, status=0)

Sends data to Photoshop.

Parameters:
  • content_type – See ContentType.
  • databytes to send.
  • transaction – transaction id.
  • status – execution status, should be 0.