The only way I have found to create a text layer is through the text_font method which accepts fontsize in pixels (not points). SelFont has to be a font object from the font chooser or using get_by_name.
mytext = Gimp.text_font(image, None, x_text, y_text, text, border, antialias, fontsize, SelFont)
Hope that helps
Thanks for that.
It works, but unfortunately, this one doesn’t let me specify a parent.
And I can’t find a way to move layers into a group.
So I’ll just have to wait until we can tell the proper function
(something like Gimp.TextLayer.new() ?)
how to set “pixels”
The GimpUnit implementation is a very weird exception and probably one of the reasons to break our old API is getting rid of this technical debt.
GimpUnit is a weird combination of an enum that is merged into a class behind the scenes. Gobject introspection that is used for our new API fails to correctly interpret this.
Untangling this is one of the last things left for the 3.0 API.
I can’t stand that multi-line sequence, it’s impossible to remember and it’s too easy to forget a line or two, so I use a wrapper.
def run_pdb(procname, argdict):
global pdb
if not pdb:
pdb = Gimp.get_pdb()
pdb_proc = pdb.lookup_procedure(procname)
pdb_config = pdb_proc.create_config()
for argname in argdict:
pdb_config.set_property(argname, argdict[argname])
vals = pdb_proc.run(pdb_config)
# Convert to an iterable list
return [ vals.index(i) for i in range(vals.length()) ]
# How to call it
result = run_pdb('gimp-file-save', {
'run-mode': Gimp.RunMode.NONINTERACTIVE,
'image': image,
'file': Gio.File.new_for_path(filepath)
})
I’m sure I’ll have to tweak it as time goes by and the API changes. I’d like to see something more like this in the official API.
I personally don’t mind that multi-line sequence (if I can’t find a one-liner).
I can copy it from the procedure browser, so no fear to forget anything.
I find it much better than in GIMP 2.10, because the parameters are recognizable by names. It’s not just that you have to put in a value for position 37 or so (for map-object, for example).
Like you I have been trying to use this but without success. I have tried all sorts of combinations but just get error messages. eg for Gimp.Unit.PIXEL i get AttributeError: type object ‘Unit’ has no attribute ‘PIXEL’. It would be useful if it then gave a suggestion!
@nelo, @JimDee2 And Jehan just fixed the issue with Gimp.Unit.pixel(), so that’ll work in 3.0 and the next nightly Flatpak. Thank for pointing out the issue!
The fact it didn’t work with Gimp.Unit.pixel() was a bug (the function’s arg’s range was wrongly set and simply refused pixel unit). It has been fixed for anyone using the HEAD of our main development branch.