spinhead Posted June 13, 2020 Posted June 13, 2020 I'm considering the move from Photoshop to AFPhoto. A script I use every day in Photoshop is to separate a text layer word by word into layers, one word per layer. From what I read Photo doesn't support scripting, but how would I go about doing this with macros? I can't even conceptualize the process. I'm a coder from way back, so I'm hoping the Affinity tools will eventually allow scripting. Thanks. Quote
v_kyr Posted June 13, 2020 Posted June 13, 2020 1 hour ago, spinhead said: A script I use every day in Photoshop is to separate a text layer word by word into layers, one word per layer. .... but how would I go about doing this with macros? I can't even conceptualize the process. Well I don't see much chances here for macros, since there aren't any text string splitting functions available, which would allow to automate somehow such a process. - So you would probably have to pre-generate before the text into several seperated word layers (let's say via scripting together some SVG code etc.), which you then would import or copy over as SVG into APh. So something like this here: #!/usr/local/bin/python3 import argparse def split_text(text): words = text.split() xpos = 10 ypos = 10 print("<?xml version=\"1.0\" encoding=\"utf-8\"?>") print("<!-- Generated by text2words.py -->") print("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">") print("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\" viewBox=\"0 0 200 200\">") for wd in words: print("<g id=\"" + wd + "\">") print(" <text x=\"" + str(xpos) + "\" y=\"" + str(ypos) + "\">" + wd + "</text>") print("</g>") ypos += 10 print("</svg>\n") if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("textstr", help="a text string to be split into words") args = parser.parse_args() theText = args.textstr if not theText == "": print("Splitting the given text into SVG word layers now ...\n") split_text(theText) Which would be run like this with a given text sentence of "It rains cats and dogs" then for generating the SVG code: > python3 text2words.py "It rains cats and dogs" Splitting the given text into SVG word layers now ... <?xml version="1.0" encoding="utf-8"?> <!-- Generated by text2words.py --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200" viewBox="0 0 200 200"> <g id="It"> <text x="10" y="10">It</text> </g> <g id="rains"> <text x="10" y="20">rains</text> </g> <g id="cats"> <text x="10" y="30">cats</text> </g> <g id="and"> <text x="10" y="40">and</text> </g> <g id="dogs"> <text x="10" y="50">dogs</text> </g> </svg> The SVG result imported into AD/APh would look like this: Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2
spinhead Posted June 13, 2020 Author Posted June 13, 2020 That's madness. Did you whip that up just to answer my question? I am awed. Thank you so much for a truly meaningful response. Designer is probably a better place for typographic art. I never learned Illustrator so Photoshop is my hammer for ever nail. I still need photo manipulation software, but if I can bring scripting to both Designer and Photo, I'm chuffed. Thanks muchly, @v_kyr Quote
v_kyr Posted June 13, 2020 Posted June 13, 2020 4 hours ago, spinhead said: Did you whip that up just to answer my question? I thought maybe this is a little more meaningful, when you see that you always would need some sort of workarounds for Affinity products here, since they sadly do miss own scripting capabilities. APhoto's macro capabilities are pretty limited (weak) in comparison to what "Photoshop actions" or "Photoshop scripting" offer. 4 hours ago, spinhead said: I still need photo manipulation software, but if I can bring scripting to both Designer and Photo, I'm chuffed. Well you actually can't, since no Affinity product realy supports any sort of scripting. The above is just an Affinity independent Python script, which is completely unrelated to Affinity software. It's just a little workaround, so one can still use APhoto at all then. Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2
R C-R Posted June 13, 2020 Posted June 13, 2020 11 hours ago, spinhead said: A script I use every day in Photoshop is to separate a text layer word by word into layers, one word per layer. Just curious, but why would you want to do that? Considering the extensive (if sometimes confusing) text handling options in the Affinity apps, I would think that breaking text into separate word objects would rarely if ever be needed. Quote All 3 1.10.8, & all 3 V2.5.7 Mac apps; 2020 iMac 27"; 3.8GHz i7, Radeon Pro 5700, 32GB RAM; macOS 10.15.7 All 3 V2 apps for iPad; 6th Generation iPad 32 GB; Apple Pencil; iPadOS 15.7
spinhead Posted June 13, 2020 Author Posted June 13, 2020 @v_kyr Understood. But scripting in conjunction with the tools is, for me, as good as scripting within the tools. And Python isn't difficult. Since my real decision is "pay Adobe $10/month forever" or "pay Serif $25 once" I'm only looking for an absolute deal-breaker to make me stay with Photoshop. Thanks to your comment, this is not that. @R C-R I create typographical posters from my song lyrics, like this one. In Photoshop it became immediately apparent that since I was using multiple sizes and weights in a nonlinear layout, separate layers were required. If Affinity Designer or Photo obviates the need, all the better. Thanks for raising the question. R C-R 1 Quote
lepr Posted June 13, 2020 Posted June 13, 2020 13 minutes ago, spinhead said: @R C-R I create typographical posters from my song lyrics, like this one. In Photoshop it became immediately apparent that since I was using multiple sizes and weights in a nonlinear layout, separate layers were required. If Affinity Designer or Photo obviates the need, all the better. Thanks for raising the question. The best solution for your needs is a separate object for each word. It would be a nightmare to manipulate a single paragraph to look like your example, even if it is possible. R C-R 1 Quote
Wosven Posted June 13, 2020 Posted June 13, 2020 @v_kyr, The groups can be skipper in the script, to have only word objects (text tags). They don't need ID, since the word is readable as the object's name in the layers panel. Quote
v_kyr Posted June 13, 2020 Posted June 13, 2020 28 minutes ago, Wosven said: @v_kyr, The groups can be skipper in the script, to have only word objects (text tags). They don't need ID, since the word is readable as the object's name in the layers panel. I know, for the above shown I just reused one of my python script templates here, which instead was build for other SVG creations with ID numberings. - But the code can be easily adapted to just build one group on demand by writing the group related SVG codes outside of the used for loop ... #!/usr/local/bin/python3 import argparse def split_text(text): words = text.split() xpos = 10 ypos = 10 print("<?xml version=\"1.0\" encoding=\"utf-8\"?>") print("<!-- Generated by text2words.py -->") print("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">") print("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"200\" height=\"200\" viewBox=\"0 0 200 200\">") print("<g id=\"text_group\">") ### start before loop for wd in words: print(" <text x=\"" + str(xpos) + "\" y=\"" + str(ypos) + "\">" + wd + "</text>") ypos += 10 print("</g>") ### close after loop print("</svg>\n") if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("textstr", help="a text string to be split into words") args = parser.parse_args() theText = args.textstr if not theText == "": print("Splitting the given text into SVG word layers now ...\n") split_text(theText) ------------------------------------------------------------------------ <?xml version="1.0" encoding="utf-8"?> <!-- Generated by text2words.py --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200" viewBox="0 0 200 200"> <g id="text_group"> <text x="10" y="10">Cats</text> <text x="10" y="20">and</text> <text x="10" y="30">dogs</text> <text x="10" y="40">flying</text> <text x="10" y="50">around</text> </g> </svg> ... etc ... ... or to write out the SVG code with no group generation at all. Wosven 1 Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2
spinhead Posted June 20, 2020 Author Posted June 20, 2020 Here's the process I've settled on, using processes I already know well: 1. copy/paste the text from my songs, poems, and stories into VS Code 2. replace spaces with carriage returns 3. lower case all (these two steps are trivial in VS Code) 4. In Google sheets, paste the word list 5. I have columns of x and y coordinates, and lookup tables for font-size (by the word's part of speech) and weight (inverse by size; big text = thin weight) 6. type in the part of speech for each word (may eventually automate with a dictionary lookup, because I'm a command line junkie) 7. copy pre-created code for each line (formulae etc. concatenate it all) thusly: <text x="128px" y="256px" style="font-family:'Helvetica Neue';font-size:30px;font-weight:500;">because</text> 8. stick it all in the svg document 9. open in Designer and fiddle Yes, Designer. I did buy Photo, but among the other good hints and tips in this thread I realized Designer is better for my text-based art. Thanks, one and all. joel Quote
v_kyr Posted June 20, 2020 Posted June 20, 2020 9 hours ago, spinhead said: Here's the process I've settled on, using processes I already know well: ... That literally cries out for scripting and automating all or some of the involved processing then. VScode can be pretty useful here to build/write some Python, Ruby, Perl, LUA ... or whatever solution for that, since it supports coding, executing, testing and debugging for all those languages. - Further all of those scripting languages can deal pretty well with strings and chars, be it parsing and splitting at given occurences of chars, conversion to lower/upper case, putting and retrieving strings/chars into some data structure (ordered or unordered), the random access of strings ... etc. etc. So you can easily build your specific/custom song lyrics to SVG format typographical poster generator with some of those script languages for quick turnarounds. Fine tuning, words repositioning, font attribute changing etc. can then been done afterwards in AD or APh. Quote ☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan ☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2
spinhead Posted June 20, 2020 Author Posted June 20, 2020 Indeed. Chipping away first at getting the parameters sorted in the tools I know best, then I'll be streamlining it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.