使用命令行使用“可编辑文本”创建多层psd文件

时间:2020-12-20 08:58:09

I am trying to create a PSD file using command line (linux/osx). Example: I have 5 blocks of text

我正在尝试使用命令行(linux / osx)创建一个PSD文件。示例:我有5个文本块

"hello" "this" "is" "an" "example"

“你好”“这个”“是”“一个”“例子”

I need a way to take these 5 blocks of text and generate a psd that will have 5 different layers for each text block and i need them to be editable after the psd has been generated and opened in photoshop.

我需要一种方法来获取这5个文本块并生成一个psd,每个文本块将有5个不同的层,我需要它们在psd生成并在photoshop中打开后可编辑。

Are you guys familiar with any software that can do this?

你们熟悉任何可以做到这一点的软件吗?

I tried GIMP and ImageMagick and i was able to generate a psd with 5 layers with the text blocks in there but unfortunately imageMagick seems to turn the text into an actual image so this makes the text non editable once opened up in photoshop.

我尝试了GIMP和ImageMagick,我能够生成一个带有5层文本块的psd,但不幸的是,imageMagick似乎将文本转换为实际图像,因此这使得文本在photoshop中打开后不可编辑。

2 个解决方案

#1


0  

You can use Applescript or Extendscript to script Photoshop itself - there is a guide available here.

您可以使用Applescript或Extendscript来编写Photoshop本身的脚本 - 这里有一个指南。

You can do something like this using the Applescript version:

您可以使用Applescript版本执行以下操作:

tell application "Finder" to set thePath to (home as string) & "TestText.tif"
set thePosix to quoted form of POSIX path of thePath
display dialog thePosix
do shell script "touch " & thePosix

tell application "Adobe Photoshop CC"
    activate
    make new document with properties {name:"Testtextlayers"}
    make new art layer at current document with properties {kind:text layer}
    make new art layer at current document with properties {kind:text layer}
    tell text object of art layer 1 of current document
        set {contents, size, stroke color} to {"Hello", 30.0, {class:RGB hex color, hex value:"913b8e"}}
    end tell
    tell text object of art layer 2 of current document
        set {contents, size, stroke color, position} to {"World", 48.0, {class:RGB hex color, hex value:"339966"}, {3, 4}}
    end tell
    set myOptions to {class:TIFF save options, image compression:none, byte order:Mac OS, save alpha channels:true, save spot colors:true, embed color profile:true}
    save current document in file thePath as TIFF with options myOptions appending no extension without copying

end tell

The Extendscript version may be more portable across Linux and Windows.

Extendscript版本可能在Linux和Windows上更具可移植性。

#2


0  

Indeed - most software able to manipulate PSD images can only work with a subset of it. GIMP itself will only open text PSD layers as pixels.

实际上 - 大多数能够操纵PSD图像的软件只能使用它的一部分。 GIMP本身只会将文本PSD图层打开为像素。

My hint for your workflow would be to script this from inside photoshop, and create another kind of file, with text-markup, that would be rendered there. Doing that would not be possible through the command line, though - (maybe it could be automated with GUI automation tools).

我对你的工作流程的暗示是从photoshop内部编写脚本,并创建另一种带有文本标记的文件,该文件将在那里呈现。但是,通过命令行无法做到这一点 - (也许可以通过GUI自动化工具实现自动化)。

Ah - it just hit me - maybe you could work with the SVG file format, and have it converted to PSD later (the conversion would still require manual interaction inside Photoshop though - but maybe the SVG file is close enough you can ship it directly to your final users, isntead of a PSD)

啊 - 它只是打了我 - 也许你可以使用SVG文件格式,并将其转换为PSD(虽然转换仍然需要在Photoshop内部进行手动交互 - 但也许SVG文件足够接近你可以直接发送到你的最终用户,而不是PSD)

As for an SVG approach: create a new template file in Inskcape, and possition your 5 blocks of text wherever you like. The final result will contain your text in XML blocks looking like this:

至于SVG方法:在Inskcape中创建一个新的模板文件,并在任何你喜欢的地方放置5块文本。最终结果将包含XML块中的文本,如下所示:

<text
   xml:space="preserve"
   style="font-size:40px;...font-family:Sans"
   x="140"
   y="123.79075"
   id="text2999"
   sodipodi:linespacing="125%"><tspan
     sodipodi:role="line"
     id="tspan3001"
     x="140"
     y="123.79075">MyText here</tspan></text>

Replace the actual text (My text here) whtih a markup such as {}, and then you can create your svg files with a python oneliner such as:

用{}之类的标记替换实际文本(我的文本),然后你可以使用python oneliner创建你的svg文件,例如:

python -c "import sys; open(sys.argv[2], 'wt').write(open(sys.argv[1]).read().format(*sys.argv[3:])  )" template.svg drawing.svg My other text file shines

The advantage of this approach is that you can actually style and format the template in very detailed ways. (hmm..browsing around, it looks like photoshop can't simply open SVG files...too bad anyway - maybe you can swithch your needed workflow away from it?)

这种方法的优点是您可以以非常详细的方式实际设置样式和格式化模板。 (嗯......浏览一下,看起来photoshop不能简单地打开SVG文件......反正太糟糕了 - 也许你可以将你需要的工作流程从它上面转开?)

#1


0  

You can use Applescript or Extendscript to script Photoshop itself - there is a guide available here.

您可以使用Applescript或Extendscript来编写Photoshop本身的脚本 - 这里有一个指南。

You can do something like this using the Applescript version:

您可以使用Applescript版本执行以下操作:

tell application "Finder" to set thePath to (home as string) & "TestText.tif"
set thePosix to quoted form of POSIX path of thePath
display dialog thePosix
do shell script "touch " & thePosix

tell application "Adobe Photoshop CC"
    activate
    make new document with properties {name:"Testtextlayers"}
    make new art layer at current document with properties {kind:text layer}
    make new art layer at current document with properties {kind:text layer}
    tell text object of art layer 1 of current document
        set {contents, size, stroke color} to {"Hello", 30.0, {class:RGB hex color, hex value:"913b8e"}}
    end tell
    tell text object of art layer 2 of current document
        set {contents, size, stroke color, position} to {"World", 48.0, {class:RGB hex color, hex value:"339966"}, {3, 4}}
    end tell
    set myOptions to {class:TIFF save options, image compression:none, byte order:Mac OS, save alpha channels:true, save spot colors:true, embed color profile:true}
    save current document in file thePath as TIFF with options myOptions appending no extension without copying

end tell

The Extendscript version may be more portable across Linux and Windows.

Extendscript版本可能在Linux和Windows上更具可移植性。

#2


0  

Indeed - most software able to manipulate PSD images can only work with a subset of it. GIMP itself will only open text PSD layers as pixels.

实际上 - 大多数能够操纵PSD图像的软件只能使用它的一部分。 GIMP本身只会将文本PSD图层打开为像素。

My hint for your workflow would be to script this from inside photoshop, and create another kind of file, with text-markup, that would be rendered there. Doing that would not be possible through the command line, though - (maybe it could be automated with GUI automation tools).

我对你的工作流程的暗示是从photoshop内部编写脚本,并创建另一种带有文本标记的文件,该文件将在那里呈现。但是,通过命令行无法做到这一点 - (也许可以通过GUI自动化工具实现自动化)。

Ah - it just hit me - maybe you could work with the SVG file format, and have it converted to PSD later (the conversion would still require manual interaction inside Photoshop though - but maybe the SVG file is close enough you can ship it directly to your final users, isntead of a PSD)

啊 - 它只是打了我 - 也许你可以使用SVG文件格式,并将其转换为PSD(虽然转换仍然需要在Photoshop内部进行手动交互 - 但也许SVG文件足够接近你可以直接发送到你的最终用户,而不是PSD)

As for an SVG approach: create a new template file in Inskcape, and possition your 5 blocks of text wherever you like. The final result will contain your text in XML blocks looking like this:

至于SVG方法:在Inskcape中创建一个新的模板文件,并在任何你喜欢的地方放置5块文本。最终结果将包含XML块中的文本,如下所示:

<text
   xml:space="preserve"
   style="font-size:40px;...font-family:Sans"
   x="140"
   y="123.79075"
   id="text2999"
   sodipodi:linespacing="125%"><tspan
     sodipodi:role="line"
     id="tspan3001"
     x="140"
     y="123.79075">MyText here</tspan></text>

Replace the actual text (My text here) whtih a markup such as {}, and then you can create your svg files with a python oneliner such as:

用{}之类的标记替换实际文本(我的文本),然后你可以使用python oneliner创建你的svg文件,例如:

python -c "import sys; open(sys.argv[2], 'wt').write(open(sys.argv[1]).read().format(*sys.argv[3:])  )" template.svg drawing.svg My other text file shines

The advantage of this approach is that you can actually style and format the template in very detailed ways. (hmm..browsing around, it looks like photoshop can't simply open SVG files...too bad anyway - maybe you can swithch your needed workflow away from it?)

这种方法的优点是您可以以非常详细的方式实际设置样式和格式化模板。 (嗯......浏览一下,看起来photoshop不能简单地打开SVG文件......反正太糟糕了 - 也许你可以将你需要的工作流程从它上面转开?)