Photoshop的自动插入来自文件的文本
-
22-08-2019 - |
题
我有一个多语言网站,需要自动从csv源更新在PSD-文件textlayers的过程。
我知道,有可能是因为改变宽度的PSP毛刺,但无论如何,它会帮助很多有文档中的文本。
我有哪些选择?
编辑:
Murmelschlurmel具有工作溶液。这里是链接到Adobe文档。
的CSV文件的格式是不是很好:你需要一个柱为每个变量。我希望每个变量一行。
它与元音变音(ä,ö等)
EDIT 1:
另一种解决方案是使用COM自动化的Photoshop。如果你有一对夫妇的需要更改的文本模板(按钮)那是很好的。这里是我的Python脚本,可能让你startet。
您需要与列的Excel文件: TemplateFileName,TargetFileName,TargetFormat,文本 (即template.psd,按钮1,GIF,NiceButton)。 未使用的片材的第一行。 在PSP模板应该只有1个textlayer和不能有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中使用的词。
下面是如何进行的:
装入图像在Photoshop,并与限定的变量图片>变量>定义强>
然后您的CSV转换为格式Photoshop可以读取。我有最好的经验标签,delimted文本
最后加载在Photoshop中的文本文件与图片>变量>数据集并让Photoshop中保存所有迭代。
当我尝试这第一次,我发现,Photoshop的帮助文件没有提供足够的细节。我在网上搜索了 Photoshop的“数据集” ,并发现了一些很好的教程,例如这一个从 digitaltutors 。
其他提示
这可能是有点过太多了,但我已经使用的Adobe AlterCast / Grphics服务器来处理完全相同的问题。
此外,如果它只是文字GIF / JPG图像,您可以使用Python + PIL(Python图像库)。 下面是一个示例代码(适用于Windows OS安装Arial和大阪的字体。)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import ImageFont, ImageDraw, Image
#font = ImageFont.truetype("/usr/share/fonts/bitstream-vera/Vera.ttf", 24)
#font = ImageFont.truetype("futuratm.ttf", 18)
font = ImageFont.truetype("arial.ttf", 18)
im = Image.new("RGB", (365,20), "#fff")
draw = ImageDraw.Draw(im)
draw.text((0, 0), "Test Images", font=font, fill="#000")
im.save("TestImg_EN.gif", "GIF")
font = ImageFont.truetype("osaka.ttf", 18)
im = Image.new("RGB", (365,20), "#fff")
draw = ImageDraw.Draw(im)
draw.text((0, 0), u"テストイメージ", font=font, fill="#000")
im.save("TestImg_JP.gif", "GIF")