LoginSignup
8
8

More than 5 years have passed since last update.

Python で psd ファイルを png に変換する

Last updated at Posted at 2014-11-24

kmike/psd-tools を使う.
まず以下を pip で入れる.

pip install psd-tools
pip install Pillow
pip install packbits

コマンドラインから path を指定して, 変換してくれると嬉しいのでそのように作る.

from psd_tools import PSDImage
import sys
import os

def isfilepath(path):
    print(path)
    return os.path.isfile(os.path.abspath(os.path.expanduser(path)))

def ispsd(path):
    if path[-3:] == 'psd':
        return True
    return False

def pngpath(path):
    return path[:-3] + 'png'

file_paths = [file_path for file_path in sys.argv if isfilepath(file_path) and ispsd(file_path)]
for file_path in file_paths:
    psd = PSDImage.load(file_path)
    merged_image = psd.as_PIL()
    merged_image.save(pngpath(file_path))

これを psdtopng.py として保存してコマンドラインから叩く.

python psdtopng.py ~/Desktop/hoge.psd

すると, ~/Desktop/hoge.png が出力される:congratulations:

sqrtxx/psdtopng

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8