Thibault Molleman
Thibault Molleman

Reputation: 57

How to change text layer in GIMP?

I have a gimp file that I'm using as a template.

I'm trying to find a way to script something so that I can easily replace the template text in that file to something that I specify.

Cheers

Upvotes: 0

Views: 1054

Answers (1)

xenoid
xenoid

Reputation: 8914

To get you started:

The information of a text layer (text, fonts and other options) is kept in a "parasite". This "parasite" is created when the image is saved (no such parasite on a freshly created text layer). It can be retrieved and the information reused. IMHO it will be easier to recreate a new layer anyway. In Python:

def text_info(img,layer):
    parasites=None
    try:
        parasites=layer.parasite_list()
    except Exception as e:
        pass;
    if parasites and 'gimp-text-layer' in parasites:
        data=layer.parasite_find('gimp-text-layer').data
        pdb.gimp_message('Text layer "%s": %s' % (layer.name,data))
    else:
        pdb.gimp_message('No text information found for layer "%s"' % layer.name)

Code lifted from the text-info script/plugin that you'll find here

enter image description here

Text layer "TEXT ...": (text "TEXT\nEXAMPLE")
(font "Roboto Heavy")
(font-size 60)
(font-size-unit pixels)
(antialias yes)
(language "en")
(base-direction ltr)
(color (color-rgb 0 0 0))
(justify center)
(box-mode dynamic)
(box-unit pixels)
(hinting yes)

Upvotes: 3

Related Questions