psd2pngs package

psd2pngs.convert(psd_path: Union[str, Path], out_dir_path: Optional[Union[str, Path]] = None, single_process: bool = False, n_tasks: int = 2, use_json: bool = False, use_json_camel_case: bool = False, json_only: bool = False)[source]

Convert a PSD file to multiple PNG files. When multiprocessing, since pickling Layers are very slow, each process will open the PSD file separately.

Parameters
  • psd_path (str) – Path to the PSD file.

  • out_dir_path (Optional[str], optional) – Output directory, by default None

  • single_process (bool, optional) – Do not use multiprocessing, by default False

  • n_tasks (int, optional) – Number of tasks when multiprocessing is used, by default multiprocessing.cpu_count() (Number of CPU Threads)

  • use_json (bool, optional) – Whether to output a json file (snake_case), by default False

  • use_json_camel_case (bool, optional) – Whether to output a json file (camelCase), by default False

  • json_only (bool, optional) – Only generates a json file and do not convert the file, by default False

Raises
  • ValueError – Raises if the suffix of the PSD file is not “.psd”.

  • ValueError – Raises if use_json and use_json_camel_case are both True.

  • ValueError – Raises if use_json and use_json_camel_case are both False but json_only is True.

Submodules

psd2pngs.convertion module

psd2pngs.convertion.convert(psd_path: Union[str, Path], out_dir_path: Optional[Union[str, Path]] = None, single_process: bool = False, n_tasks: int = 2, use_json: bool = False, use_json_camel_case: bool = False, json_only: bool = False)[source]

Convert a PSD file to multiple PNG files. When multiprocessing, since pickling Layers are very slow, each process will open the PSD file separately.

Parameters
  • psd_path (str) – Path to the PSD file.

  • out_dir_path (Optional[str], optional) – Output directory, by default None

  • single_process (bool, optional) – Do not use multiprocessing, by default False

  • n_tasks (int, optional) – Number of tasks when multiprocessing is used, by default multiprocessing.cpu_count() (Number of CPU Threads)

  • use_json (bool, optional) – Whether to output a json file (snake_case), by default False

  • use_json_camel_case (bool, optional) – Whether to output a json file (camelCase), by default False

  • json_only (bool, optional) – Only generates a json file and do not convert the file, by default False

Raises
  • ValueError – Raises if the suffix of the PSD file is not “.psd”.

  • ValueError – Raises if use_json and use_json_camel_case are both True.

  • ValueError – Raises if use_json and use_json_camel_case are both False but json_only is True.

psd2pngs.layer_info module

class psd2pngs.layer_info.LayerInfo(local_path: str, name: str, safe_name: str, is_visible: bool, is_group: bool, children: Iterable[LayerInfo])[source]

Bases: NamedTuple

Layer information.

children: Iterable[LayerInfo]

LayerInfos of the child layers. Empty list if not a group.

is_group: bool

Whether the layer is a group.

is_visible: bool

Whether the layer is visible.

local_path: str

The local path to the layer. The file name is safe_name.png.

name: str

The name of the layer.

safe_name: str

The safe name (which could be used as a file name) of the layer.

psd2pngs.layer_info.get_layer_info(layer: PSDImage, current_local_path: Path = PosixPath('.')) LayerInfo[source]

Get LayerInfo for the given layer. Recursively get LayerInfo for all children.

Parameters
  • layer (PSDImage) – The base layer.

  • current_local_path (Path, optional) – The base path to use for LayerInfo[“local_path”], by default Path(“”)

Returns

The LayerInfo for the given layer.

Return type

LayerInfo

psd2pngs.layer_save module

class psd2pngs.layer_save.ImageLayerInfo(absolute_path: Path, layer: Layer)[source]

Bases: NamedTuple

Layer and

Parameters
  • absolute_path (Path) – The absolute path to output the image.

  • layer (Layer) – The layer to output.

absolute_path: Path

The absolute path to output the image.

layer: Layer

The layer to output.

psd2pngs.layer_save.save_layer(image_size: tuple[int, int], layer_info: ImageLayerInfo) None[source]

Save the given layer (layer_info[‘layer’]) to the given path (layer_info[‘absolute_path’]) using PIL.

Parameters
  • image_size (tuple[int, int]) – The size of the root layer (any layer which you want it to be based on). psd.size is Recommended.

  • layer_info (ImageLayerInfo) – The layer and absolute path to save the layer to.

psd2pngs.layer_save.save_some_layers(psd_path: Path, out_dir_path: Path, layer_indcies: Iterable[int])[source]

Open the PSD file and save the given layers to the given path. The expected use case of this function is to use as a multiprocessing function. (Because heavy layers do not have to be pickled.)

Parameters
  • psd_path (Path) – The path to the PSD file.

  • out_dir_path (Path) – The base absolute path to create a folder in which layers will be saved.

  • layer_indcies (Iterable[int]) – Indcies (for search_all_layers()) of the layers to save.

psd2pngs.layer_save.search_all_layers(layer: Union[Layer, PSDImage], current_absolute_path: Path) Generator[ImageLayerInfo, None, None][source]

Get all ImageLayerInfos under the given layer. Recursively get all ImageLayerInfos for all children.

Parameters
  • layer (Layer) – The base layer.

  • current_absolute_path (Path) – The base absolute path to use for ImageLayerInfo[“absolute_path”]

Yields

Generator[ImageLayerInfo, None, None] – ImageLayerInfos for all layers.

psd2pngs.safe_name module

psd2pngs.safe_name.get_safe_name(name: str) str[source]

Get a safe name that could be used as a file name for the given name. ‘*’ will be replaced with ‘-’ and the rest will be replaced with ‘_’. (For better compatibility with PSDToolKit (well-known AviUtl Plugin))

Parameters

name (str) – The name to get a safe name for.

Returns

The safe name.

Return type

str

psd2pngs.unpack module

psd2pngs.unpack.isnamedtupleinstance(obj: object) bool[source]

Check if the given object is a namedtuple.

Parameters

x (object) – object to check.

Returns

True if the given object is a namedtuple.

Return type

bool

psd2pngs.unpack.unpack_nested_namedtuple(obj: object) object[source]

Unpack a nested namedtuple to a dict.

Parameters

obj (object) – object to unpack.

Returns

Unpacked object.

Return type

object

psd2pngs.version module