python:imagesprocess
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| python:imagesprocess [2014/08/15 06:19] – [Read header and layers(contain layers and groups)] admin | python:imagesprocess [2022/10/29 16:15] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Image Processing ====== | ====== Image Processing ====== | ||
| + | ===== Pillow ===== | ||
| + | refer: http:// | ||
| + | ==== Image Module ==== | ||
| + | ==== ImageDraw Module ==== | ||
| ===== Psd tools ===== | ===== Psd tools ===== | ||
| source: https:// | source: https:// | ||
| + | refer API: http:// | ||
| ==== Install ==== | ==== Install ==== | ||
| * windows:< | * windows:< | ||
| SET VS90COMNTOOLS=%VS100COMNTOOLS% | SET VS90COMNTOOLS=%VS100COMNTOOLS% | ||
| - | easy_install.ext psd-tools | + | easy_install.exe psd-tools |
| easy_install.exe packbits | easy_install.exe packbits | ||
| </ | </ | ||
| Line 13: | Line 18: | ||
| </ | </ | ||
| ==== Using Psd tools ==== | ==== Using Psd tools ==== | ||
| - | === Read header | + | === Read psd file and get header, |
| - | PSDImage.layers | + | |
| - | <code python> | + | * **psd_tools.user_api.psd_image.PSDImage** |
| + | Basic Examples: | ||
| + | * Read header and layers:<code python> | ||
| from psd_tools import PSDImage | from psd_tools import PSDImage | ||
| Line 26: | Line 33: | ||
| | | ||
| </ | </ | ||
| - | === working with group === | + | * Save all layers and groups:< |
| - | === working with layer === | + | from psd_tools import PSDImage |
| + | from psd_tools.user_api.psd_image import PSDImage as UserImage | ||
| + | |||
| + | psd = PSDImage.load(' | ||
| + | for layer in psd.layers: | ||
| + | pil_img = layer.as_PIL() | ||
| + | pil_img.save(layer.name + ' | ||
| + | </ | ||
| + | === working with group(psd_tools.Group) | ||
| + | === working with layer(psd_tools.Layer) | ||
| + | === export psd file to png === | ||
| + | psd.as_PIL() return object **PIL.Image.Image** | ||
| + | * Simple export< | ||
| + | from psd_tools import PSDImage | ||
| + | from psd_tools.user_api.psd_image import PSDImage as UserImage | ||
| + | |||
| + | psd = PSDImage.load(' | ||
| + | merge_img = psd.as_PIL() | ||
| + | merge_img.save(' | ||
| + | </ | ||
| + | * script export psd to png file:< | ||
| + | from psd_tools import PSDImage | ||
| + | import sys, os | ||
| + | import re | ||
| + | from os import path | ||
| + | |||
| + | def convertpsd2png(psdfilename, | ||
| + | psd = PSDImage.load(psdfilename) | ||
| + | pil_img = psd.as_PIL() | ||
| + | pngfilename = re.sub(' | ||
| + | pngfilename = path.join(outpath, | ||
| + | if outpath != '' | ||
| + | os.makedirs(outpath) | ||
| + | print pngfilename | ||
| + | pil_img.save(pngfilename) | ||
| + | nargs = len(sys.argv) | ||
| + | outpath = '' | ||
| + | if nargs <= 1: | ||
| + | print ' | ||
| + | exit() | ||
| + | elif nargs >=2: | ||
| + | outpath = sys.argv[2] | ||
| + | psdfilename = sys.argv[1] | ||
| + | if path.exists(psdfilename): | ||
| + | ext = path.splitext(psdfilename)[1] | ||
| + | if ext == ' | ||
| + | convertpsd2png(psdfilename, | ||
| + | else: | ||
| + | print 'the extension of file is incorrect' | ||
| + | else: | ||
| + | print 'file is not exists:', | ||
| + | </ | ||
| + | for /F " | ||
| + | </ | ||
python/imagesprocess.1408083556.txt.gz · Last modified: (external edit)
