Divide selection using guides - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +--- Thread: Divide selection using guides (/Thread-Divide-selection-using-guides) Pages:
1
2
|
Divide selection using guides - goran - 04-14-2023 Hello, First time here Anyway, I thought it would be useful if I could tell GIMP to use current selection as area for setting guides. There is an option called New guide from selection (Images -> Guides -> New guide from selection), but this just puts 2 horizontal and 2 vertical guides along sides of selection. What I had in mind was to use current rectangular selection (or bounding box of it) and then "divide" it into equal parts by setting guides (number settable by user), either horizontally, vertically, or both. So for example, let's say I have some kind of object on my canvas, and it's already placed on the right spot. And maybe I want to do some work on the middle third. I could use measure tool, but this won't work without calculator. Another option would be using rectangular selection and then setting Rule of thirds under tool options. But choosing any tool after that results in "guides" vanishing inside of the selection, so you have to put guides manually right after making that selection, if you don't want to loose them. Also, if you need any number of divisions that's not already predefined (center, thirds, fifths...) this technique will not really work. It can be done, but it will definitely take lots of repetitive steps. So I wrote a small plugin that does exactly what I had in mind. It's not finished yet, but it works. So how do you use it? After placing it in plugin directory, it registers itself under Image -> Guides -> Divide selection using guides First you make a selection. It doesn't have to be rectangular, and if it's not it will use the bounding box of the selection for calculation. After making a selection, choose Divide selection using guides (under Image -> Guides). Enter the number of divisions you need, and that's it. Now, maybe I'm re-discovering here something that's common knowledge among gimpers, but even if that's the case, this was a good learning experience. The only problem is I'm getting lots of GEGL related errors (GIMP 2.10.32), but from what I could read here, it's not my plugin's fault. RE: Divide selection using guides - PixLab - 04-14-2023 I'm laughing right now, not about you, let me explain. I start to read your post, and reaching something like 2/3 of it, I told myself "This guy/gal looks like s/he knows what s/he is speaking about, with all example the s/he gave, what's her/his problem?" Then I came to the last 3rd part of your comment and understood you were proposing a plugin, that why I'm laughing > misunderstanding your post In all case thanks a lot for it I'll try it tomorrow (it's very late evening in my time zone), and I'm thinking already for some useful use, for sure your plugin will be useful. Again thank you very much, please have a fantastic day/evening or night. RE: Divide selection using guides - goran - 04-14-2023 (04-14-2023, 02:11 PM)PixLab Wrote: I'm laughing right now, not about you, let me explain. Well one reason I went into details is to get some feedback - is there anything else out there, how other people deal with this...? It was like, if they don't use the measure tool in combination with calculator on their phone, what do they use? Another was to convince myself that I'm not missing anything important. And that is the hard part, GIMP's UI is pretty complex, not always the most intuitive (well *of course* layer name in bold means there is no alpha channel and on top of that - AFAIK, there is no single repository of useful scripts, so lots of useful stuff is probably scattered around. So when I saw Ofnuts repository, I thought somebody with more experience must have already thought of this "divide selection with guides" problem. Especially when I realized it wasn't really that hard to write (after initial hurdle) - at least this basic version. So, I don't know - maybe I missed it, maybe there are other more effective solutions out there, maybe even in the GIMP itself, but I couldn't really find anything. Don't expect too much, it's quite basic really. But I think it could be useful. RE: Divide selection using guides - Ofnuts - 04-14-2023 (04-14-2023, 09:33 AM)goran Wrote: I could use measure tool, but this won't work without calculator.Well maybe yes... In the input fields where Gimp expects a number, you can enter expressions. For instance, to scale a 4000px image to half, instead of computing 2000 on the side, you just enter 4000/2 in the size field (and since it already contains 4000, you just add /2). RE: Divide selection using guides - PixLab - 04-15-2023 (04-14-2023, 04:46 PM)Ofnuts Wrote:(04-14-2023, 09:33 AM)goran Wrote: I could use measure tool, but this won't work without calculator.Well maybe yes... In the input fields where Gimp expects a number, you can enter expressions. For instance, to scale a 4000px image to half, instead of computing 2000 on the side, you just enter 4000/2 in the size field (and since it already contains 4000, you just add /2). I never saw an input field on the measurement tool, OP and I are speaking about this tool > (04-14-2023, 04:20 PM)goran Wrote: Don't expect too much, it's quite basic really. But I think it could be useful. I did tried today, nice and indeed it will be useful. Two things though, would it be possible to change the PF_INT to something like PF_SPINNER ? I took the freedom to slightly add 2 code lines to be able to do a Ctrl+Z at once and not have to do it multiple time (I'm no programmer, I hope it's ok) Here: Code: #!/usr/bin/env python Again thank you that's a nice script RE: Divide selection using guides - denzjos - 04-15-2023 @goran,thanks to share the plugin. Nice work, the plugin is working on gimp 2.10.34 /windows 10. RE: Divide selection using guides - goran - 04-15-2023 (04-15-2023, 04:02 AM)PixLab Wrote: I did tried today, nice and indeed it will be useful. Well I'm also new to this, but yes, from what I read PF_SPINNER requires additional argument. it's a tuple in the form of (min, max, step). So if you change these two lines: Code: (PF_INT, "x_div", "horizontal divisions", 10), with these: Code: (PF_SPINNER, "x_div", "horizontal divisions", 3, (1,10,1)), You'll get a spinner that goes from 1 to 10 with the default value of 3. If you need more, you can easily change number 10 in both lines. But after testing it I realized it sends a float instead of an int, so it messed up the range in the loop which requires int. So you'll also have to cast the values, you can just put these two lines in the beginning of the function (def line is the same as it was): Code: def divide_selection_using_guides(img, x_div, y_div): That should be it. RE: Divide selection using guides - goran - 04-15-2023 (04-15-2023, 07:50 AM)denzjos Wrote: @goran,thanks to share the plugin. Nice work, the plugin is working on gimp 2.10.34 /windows 10. Good to know! And GEGL warnings, they are still there? RE: Divide selection using guides - teapot - 04-15-2023 Hi goran, Thank you for sharing your first script. I appreciate getting into new things isn't easy so will just mention one thing. In gimp if you do the menu item: Filters -> Python-Fu -> Console Then hit the Browse button You can search for the function you want to call, so in your case gimp_selection_bounds. When that comes up hit the apply button. Then look in the console window, and copy and paste the result into your code: non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) You can use the above one line to replace the following lines you currently have (changing non_empty and image to your preferred variable names) as there is no need for the multiple calls: pdb.gimp_selection_bounds(img) selection_exists = pdb.gimp_selection_bounds(img)[0] x1=pdb.gimp_selection_bounds(img)[1] y1=pdb.gimp_selection_bounds(img)[2] x2=pdb.gimp_selection_bounds(img)[3] y2=pdb.gimp_selection_bounds(img)[4] RE: Divide selection using guides - PixLab - 04-16-2023 (04-15-2023, 11:01 AM)goran Wrote: So you'll also have to cast the values, you can just put these two lines It's not working, the plugin don't load at all |