It is currently 25 Jan 2021, 09:32
| ||||
| ||||
|
|

Text box layer centering in python-fu

Text box layer centering in python-fu
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!
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...
-
tim
- View:
|Posts
- Topic Posts: 2/5 | Posts: 5228
- Joined: 26 Sep 2016, 00:16
- Cash on hand: 75,573.53 GLP
- Bank: 215,832,827.00 GLP
- Gender: Guy
- Location: Canada
- GIMP Version: 2.10.X
- Paint Blotches blog
- Play them songs blog
- Personal Blog
- x 3072
- x 1023
- Contact:
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.
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
Out of curiosity, couldn't you program it to use the built-in alignment tool?
-
tim
- View:
|Posts
- Topic Posts: 2/5 | Posts: 5228
- Joined: 26 Sep 2016, 00:16
- Cash on hand: 75,573.53 GLP
- Bank: 215,832,827.00 GLP
- Gender: Guy
- Location: Canada
- GIMP Version: 2.10.X
- Paint Blotches blog
- Play them songs blog
- Personal Blog
- x 3072
- x 1023
- Contact:
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
| ||||
| ||||
|
-
- Similar Topics
- Replies
- Views
- Last post
-
-
How do I crop bottom layer around top layer? - SOLVED
by enxio27 » 16 Mar 2020, 01:01 » in GIMP/GL Questions - 6 Replies
- 7440 Views
-
Last post by enxio27
18 Mar 2020, 03:41
-
-
-
Python occasional "Unexpected error: [Errno 9] Bad file descriptor"
by opusGlass » 06 Mar 2020, 03:08 » in GIMP Python Fu Scripts/Plug-ins - 2 Replies
- 11965 Views
-
Last post by Wallace
09 Mar 2020, 03:09
-
-
-
Update to Version 1.21 for Custom Font Layer Utilities
by skinnyhouse » 22 Mar 2020, 15:22 » in GIMP Python Fu Scripts/Plug-ins - 2 Replies
- 2484 Views
-
Last post by Krikor
20 Dec 2020, 19:40
-
-
- 2 Replies
- 1614 Views
-
Last post by sweeneyMark
19 Jun 2020, 13:21
-
-
Custom Font Layer Utilities Version 1.22
by skinnyhouse » 20 Dec 2020, 09:21 » in GIMP Python Fu Scripts/Plug-ins - 12 Replies
- 1711 Views
-
Last post by skinnyhouse
21 Dec 2020, 20:21
-
-
-
Custom Font Layer Utilities Version 1.23 for Gimp 2.10
by skinnyhouse » 21 Dec 2020, 20:14 » in GIMP Python Fu Scripts/Plug-ins - 0 Replies
- 299 Views
-
Last post by skinnyhouse
21 Dec 2020, 20:14
-
Who is online
Users browsing this forum: No registered users and 17 guests