自动化Photoshop从文件中插入文本 [英] Automate Photoshop to insert text from file

查看:163
本文介绍了自动化Photoshop从文件中插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多语言网站,需要自动从csv源更新psd文件中文本层的过程.

I have a multilanguage website and need automate the process of updating textlayers in psd-files from a csv-source.

我知道由于宽度变化,psp中可能会出现小故障,但是无论如何,将文本包含在文档中会很有帮助.

I know that there might be glitches in the psp because of changed widths, but anyway it would help a lot to have the text inside the documents.

我有什么选择?

Murmelschlurmel有一个可行的解决方案.这是Adobe文档的链接.

Murmelschlurmel has a working solution. Here is the link to the Adobe documentation.

http://livedocs.adobe. com/en_US/Photoshop/10.0/help.html?content = WSfd1234e1c4b69f30ea53e41001031ab64-740d.html

csv文件的格式不太好:每个变量都需要一列.我希望每个变量都有一行.

The format of the csv-file is not so nice: you need a column for each variable. I would expect a row for each variable.

它与Umlaut(ä,ö等)一起使用

It works with Umlaut (ä, ö etc)

另一种解决方案是使用com来自动执行Photoshop.如果您有几个需要更改文本的模板(按钮),那就太好了.这是我的python脚本,可能会让您入门.

Another solution is to use com to automate Photoshop. Thats nice if you have a couple of templates (buttons) that need changed text. Here is my script in python that might get you startet.

您需要一个具有以下内容的Excel文件: TemplateFileName,TargetFileName,TargetFormat,文本 (即template.psd,button1,gif,NiceButton). 不使用工作表的第一行. psp模板只能有1个文字图层,不能有图层组.

You need to have an excel file with columns: TemplateFileName, TargetFileName, TargetFormat, Text (ie template.psd, button1 , gif , NiceButton) . The first row of the sheet is not used. The psp template should only have 1 textlayer and can not have layergroups.

import win32com.client
import xlrd 
spreadsheet = xlrd.open_workbook("text_buttons.xls")
sheet = spreadsheet.sheet_by_index(0)

psApp = win32com.client.Dispatch("Photoshop.Application")  
jpgSaveOptions = win32com.client.Dispatch("Photoshop.JPEGSaveOptions")  
jpgSaveOptions.EmbedColorProfile = True
jpgSaveOptions.FormatOptions = 1
jpgSaveOptions.Matte = 1
jpgSaveOptions.Quality = 1

gifSaveOptions = win32com.client.Dispatch("Photoshop.GIFSaveOptions")



for rowIndex in range(sheet.nrows):
    if(rowIndex > 0):
        template =  sheet.row(rowIndex)[0].value
        targetFile = sheet.row(rowIndex)[1].value
        targetFileFormat = sheet.row(rowIndex)[2].value
        textTranslated = sheet.row(rowIndex)[3].value
        psApp.Open(r"D:\Design\Produktion\%s" % template ) 
        doc = psApp.Application.ActiveDocument

        for layer in doc.Layers:  
            if (layer.Kind == 2):
                layer.TextItem.Contents = textTranslated
                if(targetFileFormat == "gif"):
                    doc.SaveAs(r"D:\Design\Produktion\de\%s" % targetFile, gifSaveOptions,  True, 2)
                if(targetFileFormat == "jpg"):
                    doc.SaveAs(r"D:\Design\Produktion\de\%s" % targetFile, jpgSaveOptions,  True, 2)

推荐答案

您可以使用数据驱动设计"来执行此操作.在计算机科学中,还有一个数据驱动设计的概念,但据我所知看到这与在Photoshop中使用该词无关.

You can use "Data Driven Design" to do this. There is also a concept of data driven design in computer science, but as far as I can see this is not not related to the use of the word in Photoshop.

以下是操作步骤:

在Photoshop中加载图像,然后使用图像>变量>定义来定义变量.

Load your image in Photoshop and define your variables with Image > Variable > Define.

然后将您的csv转换为Photoshop可以读取的格式.我对 tab倾斜文本有最好的体验.

Then convert your csv to a format Photoshop can read. I had the best experiences with tab delimted text.

最后使用图像>变量>数据集将文本文件加载到Photoshop中,然后让Photoshop保存所有迭代.

Finally load the text file in Photoshop with Images > Variables > Data Set and let Photoshop save all iterations.

当我第一次尝试此操作时,我发现Photoshop帮助文件没有提供足够的详细信息.我在互联网上搜索了 photoshop数据集" ,并找到了一些不错的教程,例如数字辅导员.

When I tried this first, I found that the Photoshop help file didn't provide enough details. I searched the Internet for photoshop "data set" and found some good tutorials, e.g. this one from digitaltutors.

这篇关于自动化Photoshop从文件中插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆