It is currently 13 Jul 2020, 17:40

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Text box layer centering in python-fu

GIMP or GIMP LEARN forum related Questions
vndep
Forum Member

Text box layer centering in python-fu

Post#1 by vndep » 24 Jun 2019, 16:29


Any thoughts on an efficient way to center a textbox in a python script?

For background, the script starts with an image and adds a layer of text. I want to make sure that the center of the textbox aligns with a specific X,Y coordinate in the image. To clarify, I am not thinking about left/center/right justification within the textbox.

I do not know in advance what text will be in the textbox. It could be of any length and include narrow characters (such as "i") or wide characters (such as "W")

My original thought was to somehow grab the X,Y coordinates of the four corners of the textbox (or maybe height and length) and then do some algebra to figure out to where I should move the textbox.

The only function that seems relevant is pdb.gimp_selection_bounds; however the parameter for that function is an image rather than a layer.

Anticipating a follow up question, I am not having any luck finding the python function that would allow me to move the textbox, either.

Thanks in advance!
GIMP Learn rocks...
0

tim
GL Blogger

Post#2 by tim » 24 Jun 2019, 18:58


if you use fontname function to create that layer of text the layer will be sized based on your text so it's already a good measure of your text.width and height.
That text layer will have layer.width and layer.height.
Which you could use to move around using offsets (just search for "offsets" in procedure browser in GIMP).
two functions should show up. One is to get the offsets.
The other is to set the offsets of the layer.
Use the one to set the offsets which is of the top left corner of layer.
That should be sufficient. If you want even more accuracy you can use gimp_text_get_extents_fontname but I usually get away with using created text layers width and height.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

vndep
Forum Member

Post#3 by vndep » 24 Jun 2019, 19:40


That totally works! Thanks!
GIMP Learn rocks...
1

Mapsking
Forum Member

Post#4 by Mapsking » 25 Jun 2019, 08:12


Out of curiosity, couldn't you program it to use the built-in alignment tool?
0

tim
GL Blogger

Post#5 by tim » 25 Jun 2019, 13:54


I don't think so as I type "align" into procedure browser, only one method showed up and I don't think it allows you to use it like the front end alignment tool.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0


GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 7 guests