Created
June 28, 2018 13:11
-
-
Save Baldomo/d87190a230f6360f1e1943dd5df7b72b to your computer and use it in GitHub Desktop.
Simple multithreaded PSD layer slicer and PNG exporter (created as a PS CC -> Unity 3D pipeline for pixel-art animations)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from psd_tools import PSDImage, Layer, Group | |
from sys import argv, exit | |
from multiprocessing.dummy import Pool | |
from typing import List | |
psds: List[PSDImage] = [] | |
def split_export(psd: PSDImage) -> None: | |
for el in psd.layers: | |
if isinstance(el, Layer): | |
el.as_PIL().save('./{}.png'.format(el.name)) | |
elif isinstance(el, Group): | |
for l in el.layers: | |
l.as_PIL().save('./{}.png'.format(l.name)) | |
if __name__ == '__main__': | |
if len(argv[1:]) == 0: | |
print(""" | |
Usage: | |
pipeline.py <PSD path> <PSD path>... | |
""") | |
exit(0) | |
for arg in argv[1:]: | |
psds.append(PSDImage.load(arg)) | |
pool = Pool(len(psds)) | |
pool.apply(split_export, psds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from setuptools import setup | |
setup( | |
name='pipeline', | |
install_requires=[ | |
'Pillow', | |
'psd-tools' | |
] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment