在整个产线系统中,基于windows的photoshop平台,应该是功能最强大,应用范围相对比较大的工具。所以在工作中将photoshop也纳入产线管理系统,对前期设计人员也是一件非常舒服的事情,只要本地保存好psd,一件提交上传正确的格式,尺寸,命名。并且不需要管最终输出的位置。每次提交的过程文件都会保存在服务器上,不用担心自己手残覆盖掉正确的源文件。
想想还是蛮爽的。但是ps本身没有python的开发接口。所以需要使用win32库或者java来驱动他。下面介绍一下win32库和java两种驱动方式。
import win32com.client
# Pieced together from
# http://techarttiki.blogspot.com/2008/08/photoshop-scripting-with-python.html
# and
# http://rubypane.blogspot.com/2013/01/sample-python-script-to-control.html
psApp = win32com.client.Dispatch("Photoshop.Application")
psApp.Open(r"C:\temp\blah.psd") # Opens a PSD file
doc = psApp.Application.ActiveDocument # Get active document object
layer = doc.ArtLayers[2] # Get the bottom-most layer
layers = doc.artLayers
artLayerRef = layer