RSS/Atom feed Twitter
Site is read-only, email is disabled

Copy text layers as text or python script to mass generate text layers

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

The Tick
2017-09-25 15:20:16 UTC (about 7 years ago)

Copy text layers as text or python script to mass generate text layers

This is gimp 2.8.22 on windows

I want to merge two images and both have quite a few text layers. I found that an edit->copy does not copy a text layer -- it makes it an image layer. I really do now want that since I will definitely have to modify some of the text in the future as I continue expanding the image.

1) Am I missing something? Is there a way to copy a text layer between images?
2) If not, perhaps I could write a very simple, one-time script to mass create the text layers (I'd have to move them to the correct locations but that is simpler than click-enter text-click and move for each of the layers.

I found the reference to script-fu but I have never wrapped my head around scheme/lisp and I don't want to start now. Where are the docs for the python interface? I am assuming there is some interface to create a text layer via scripting.

The Tick
2017-09-25 16:37:45 UTC (about 7 years ago)

Copy text layers as text or python script to mass generate text layers

On 9/25/2017 10:20 AM, The Tick wrote:

This is gimp 2.8.22 on windows

I want to merge two images and both have quite a few text layers. I found that an edit->copy does not copy a text layer -- it makes it an image layer. I really do now want that since I will definitely have to modify some of the text in the future as I continue expanding the image.

1) Am I missing something? Is there a way to copy a text layer between images?
2) If not, perhaps I could write a very simple, one-time script to mass create the text layers (I'd have to move them to the correct locations but that is simpler than click-enter text-click and move for each of the layers.

I found the reference to script-fu but I have never wrapped my head around scheme/lisp and I don't want to start now. Where are the docs for the python interface? I am assuming there is some interface to create a text layer via scripting.

I found the docs for gimp python; now:

1) How to get "print" statments? I started filters->python fu->console but apparently a "print" does not write to the console?

2) How can I refresh the script? So far I restart gimp but that is getting tedious.

3) Is there an online site with hints on how to debug a gimp python script?

For reference, here is the script. It apparently runs but I get no new layer and no progress/console output. I did not expect it to work first time so now I'd like some pointers on how to debug it.

from gimpfu import *

def mass_text(img) : print "Does this go to console?"

pdb.gimp.progress_init("Mass text insert ...")

font = 'Arial Bold'

pdb.gimp.set_foreground( 1.0, 0.0, 0.0 )

# Create a new text layer (-1 for the layer means create a new layer) layer = pdb.gimp_text_fontname(img, None, 0, 0, "This is my text", 10, True, 24, PIXELS, font) img.add_layer(layer, 0)

register( "python_fu_mass_text",
"Mass Text",
"Mass create text layers",
"",
"",
"",
"Mass Text Layer insert...",
"*",
[
],
[],
mass_text, menu="/Tools/MassText")

main()

2017-09-25 17:29:31 UTC (about 7 years ago)
postings
121

Copy text layers as text or python script to mass generate text layers

I found the docs for gimp python; now:

1) How to get "print" statments? I started filters->python fu->console but apparently a "print" does not write to the console?

2) How can I refresh the script? So far I restart gimp but that is getting tedious.

3) Is there an online site with hints on how to debug a gimp python script?

For reference, here is the script. It apparently runs but I get no new layer and no progress/console output. I did not expect it to work first
time so now I'd like some pointers on how to debug it.

from gimpfu import *

def mass_text(img) : print "Does this go to console?"

pdb.gimp.progress_init("Mass text insert ...")

font = 'Arial Bold'

pdb.gimp.set_foreground( 1.0, 0.0, 0.0 )

# Create a new text layer (-1 for the layer means create a new layer)
layer = pdb.gimp_text_fontname(img, None, 0, 0, "This is my text", 10,
True, 24, PIXELS, font) img.add_layer(layer, 0)

register( "python_fu_mass_text",
"Mass Text",
"Mass create text layers",
"",
"",
"",
"Mass Text Layer insert...",
"*",
[
],
[],
mass_text, menu="/Tools/MassText")

main()

1. To display information in a Python script you can use something like the following example:

pdb.gimp_message('The times are ' + str(sixteenth_time) + " " + str(eighth_time) + " " + str(quarter_time)+ " " + str(half_time))

("\n" will give you a newline(note the double quotes in this case))

2. If I remember correctly (its a while since I debugged a Python script) you just edit and save the script using a text editor and GIMP will then use the updated version when you next run the script (might be best not to save the script whilst part way through actually running the script). (For Script-Fu you also don't need to restart GIMP just use "Filters/Script-Fu/Refresh Scripts" then wait for a few seconds until the refresh is complete)

Ofnuts
2017-09-26 12:53:54 UTC (about 7 years ago)

Copy text layers as text or python script to mass generate text layers

On 09/25/17 18:37, The Tick wrote:

I found the docs for gimp python; now:

1) How to get "print" statments? I started filters->python fu->console but apparently a "print" does not write to the console?

It does for me... if you enter the "print" on the console. "Print" from a script started form a menu goes to the standard output, whicn on Linux and OSX, is the terminal from which your invoked Gimp. For Windows, things are a bit more complicated, see here: https://www.gimp-forum.net/Thread-Debugging-python-fu-scripts-in-Windows

2) How can I refresh the script? So far I restart gimp but that is getting tedious.

You don't need to, as long as you don't change the registration data. The code is reloaded from the file on each execution; so your latest chnages to the code will be taken in account.

3) Is there an online site with hints on how to debug a gimp python script?

https://www.gimp-forum.net/Thread-Debugging-python-fu-scripts-in-Windows

For reference, here is the script. It apparently runs but I get no new layer and no progress/console output. I did not expect it to work first time so now I'd like some pointers on how to debug it.

from gimpfu import *

def mass_text(img) : print "Does this go to console?"

pdb.gimp.progress_init("Mass text insert ...")

font = 'Arial Bold'

pdb.gimp.set_foreground( 1.0, 0.0, 0.0 )

# Create a new text layer (-1 for the layer means create a new layer) layer = pdb.gimp_text_fontname(img, None, 0, 0, "This is my text", 10,
True, 24, PIXELS, font)
img.add_layer(layer, 0)

register( "python_fu_mass_text",
"Mass Text",
"Mass create text layers",
"",
"",
"",
"Mass Text Layer insert...",
"*",
[
],
[],
mass_text, menu="/Tools/MassText")

main()

Try:
pdb.gimp_context_set_foreground((1.,0,0,0))

Also, the " img.add_layer(layer, 0)" isn't necessary, the layer created in gimp_text_fontname() is added to the image automatically.