简体   繁体   中英

Creating a multi layered psd file with “editable text” using command line

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

"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.

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.

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.

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).

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)

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:

<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 -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?)

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

You can do something like this using the Applescript version:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM