User Tools

Site Tools


python:imagesprocess

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:imagesprocess [2014/08/15 06:34] – [Read header and layers(contain layers and groups)] adminpython:imagesprocess [2022/10/29 16:15] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Image Processing ====== ====== Image Processing ======
 +===== Pillow =====
 +refer: http://effbot.org/imagingbook/
 +==== Image Module ====
 +==== ImageDraw Module ====
 ===== Psd tools ===== ===== Psd tools =====
 source: https://github.com/kmike/psd-tools source: https://github.com/kmike/psd-tools
 +refer API: http://searchcode.babies.vn:8080/source/xref/python2.7/site-packages/psd_tools/user_api/psd_image.py
 ==== Install ==== ==== Install ====
   * windows:<code bat>   * windows:<code bat>
 SET VS90COMNTOOLS=%VS100COMNTOOLS% SET VS90COMNTOOLS=%VS100COMNTOOLS%
-easy_install.ext psd-tools+easy_install.exe psd-tools
 easy_install.exe packbits easy_install.exe packbits
 </code> </code>
Line 13: Line 18:
 </code> </code>
 ==== Using Psd tools ==== ==== Using Psd tools ====
-=== Read header and layers(contain layers and groups) ===+=== Read psd file and get header, layers(contain layers and groups) ===
   * PSDImage.load return **psd_tools.user_api.psd_image.PSDImage** object   * PSDImage.load return **psd_tools.user_api.psd_image.PSDImage** object
   * **psd_tools.user_api.psd_image.PSDImage** contain list of objects **psd_tools.Group** and **psd_tools.Layer**   * **psd_tools.user_api.psd_image.PSDImage** contain list of objects **psd_tools.Group** and **psd_tools.Layer**
Line 41: Line 46:
 === export psd file to png === === export psd file to png ===
 psd.as_PIL() return object **PIL.Image.Image** psd.as_PIL() return object **PIL.Image.Image**
-<code python>+  * Simple export<code python>
 from psd_tools import PSDImage from psd_tools import PSDImage
 from psd_tools.user_api.psd_image import PSDImage as UserImage from psd_tools.user_api.psd_image import PSDImage as UserImage
Line 48: Line 53:
 merge_img = psd.as_PIL() merge_img = psd.as_PIL()
 merge_img.save('1203.png') merge_img.save('1203.png')
 +</code>
 +  * script export psd to png file:<code python>
 +from psd_tools import PSDImage
 +import sys, os
 +import re
 +from os import path
 +
 +def convertpsd2png(psdfilename, outpath = ''):    
 +    psd = PSDImage.load(psdfilename)
 +    pil_img = psd.as_PIL()
 +    pngfilename = re.sub('.psd', '.png', path.basename(psdfilename))
 +    pngfilename = path.join(outpath, pngfilename)
 +    if outpath != '' and not path.exists(outpath):
 +        os.makedirs(outpath)
 +    print pngfilename
 +    pil_img.save(pngfilename)
 +nargs = len(sys.argv)
 +outpath = ''
 +if nargs <= 1:
 +    print 'please input psd file'
 +    exit()
 +elif nargs >=2:
 +    outpath = sys.argv[2]
 +psdfilename = sys.argv[1]
 +if path.exists(psdfilename):
 +    ext = path.splitext(psdfilename)[1]
 +    if ext == '.psd':
 +        convertpsd2png(psdfilename, outpath)
 +    else:
 +        print 'the extension of file is incorrect'
 +else:
 +    print 'file is not exists:', psdfilename
 +</code>script to run for multiple files:<code bat>
 +for /F "delims=\r\n" %x in ('dir /B indir') do psd2png.py indir\%x outdir
 </code> </code>
python/imagesprocess.1408084496.txt.gz · Last modified: 2022/10/29 16:15 (external edit)