在影视或者游戏的制作中我们多多少少会用到Photoshop, 但是Photoshop原生不支持Python, 这样会导致我们平常在做流程的时候打通其他环节到Photoshop的难度就加到了。如果买了Ftrack或者Shotgun的公司他们自带的工具链就支持通过python去操作Photoshop除此之外就通过Python的第三方库comtypes去操作Photoshop 今天在这里我要像大家分享的是我自己写的一个python库叫photoshop_python_api 然后也感谢我的小伙伴Limbo为我这个API设计的LOGO 安装 通过pip pip install photoshop_python_api 或者通过git克隆 git clone https://github.com/loonghao/photoshop_python_api.git python setup.py install Hello World import photoshop.api as ps app = ps.Application() doc = app.documents.add() new_doc = doc.artLayers.add() text_color = ps.SolidColor() text_color.rgb.green = 255 new_text_layer = new_doc new_text_layer.kind = ps.LayerKind.TextLayer new_text_layer.textItem.contents = 'Hello, World!' new_text_layer.textItem.position = [160, 167] new_text_layer.textItem.size = 40 new_text_layer.textItem.color = text_color options = ps.JPEGSaveOptions(quality=5) # save to jpg jpg = 'd:/hello_world.jpg' doc.saveAs(jpg, options, asCopy=True) app.doJavaScript(f'alert("save to jpg: {jpg}")') 图片 由于此API是通过 COM (Component Object Model) 去连接的photoshop我可以在任何的DCC的python (必须python-3.5+)解释器上去使用此API去操作photoshop. 此API基本是对于Photoshop javescript API的一比一的翻译所以很多用法可以直接套用 比如获取当前文件名 Javascript alert(app.activeDocument.fullName) Python API from photoshop import Session with Session() as ps: ps.alert(ps.app.activeDocument.fullName) 这个API有什么优势? 自动代码补全 无其他第三方依赖, 不需要购买Shotgun或者Ftrack才能使用 这个API能为我们做些什么? 有这个API我们可以做很多事情了, 在影视行业我们可以写photoshop端的发布工具,可以在MP或者Concept画完后在photoshop中直接发布到下游,可以看看我利用这个API做了pyblish的集成 https://github.com/pyblish/pyblish-photoshop 还可以做自动加水印的功能 可以参考这个例子 """Add slate information dynamically. - Open template. - Update info. - Save as jpg. - Close current document. """ import os from datetime import datetime from tempfile import mkdtemp from photoshop import Session import examples._psd_files as psd # Import from examples. PSD_FILE = psd.get_psd_files() slate_template = PSD_FILE["slate_template.psd"] with Session(slate_template, action="open", auto_close=True) as ps: layer_set = ps.active_document.layerSets.getByName("template") data = { "project name": "test_project", "datetime": datetime.today().strftime("%Y-%m-%d"), } for layer in layer_set.layers: if layer.kind == ps.LayerKind.TextLayer: layer.textItem.contents = data[layer.textItem.contents.strip()] jpg_file = os.path.join(mkdtemp("photoshop-python-api"), "slate.jpg") ps.active_document.saveAs(jpg_file, ps.JPEGSaveOptions()) print(f"Save jpg to {jpg_file}") os.startfile(jpg_file) examples/add_slate.py 在游戏行业我们可以利用此API,改善UI们的工具流,可以写类似于把photoshop的当前文件转成cocos工程文件或者自动输出UI文件的工具 更多例子,大家可以去这里看看 https://photoshop-python-api.readthedocs.io 现在这个API还没完全写完,但是已经能满足我们现在工作中大部分使用情况了 |
大家都知道静态网页有利于SEO,但是很多新手在使用DZ论坛程序的时候不懂,很多人在问DZ
牛逼牛逼,之前的论坛应该见我发过,未来是即时渲染的天下,并且U-render 最有潜力很
所有版本官方配置单请点击链接:https://knowledge.autodesk.com/z ... -Autodesk-May
https://www.acfun.cn/player/ac11550103
Autodesk最近发布了3D模型动画软件Maya 2020.2和Maya LT 2020.2新功能的在线文档,两
https://player.bilibili.com/player.html?aid=74213651cid=127467367page=1