Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Divide selection using guides
#5
(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 > Measure

(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

#
# https://www.gimp-forum.net/Thread-Divide-selection-using-guides
#

from gimpfu import *
#img = gimp.image_list()[0]

def divide_selection_using_guides(img, x_div, y_div):
    pdb.gimp_image_undo_group_start(img)
    
    if x_div==0 or x_div=="":
        x_div=1
    if y_div==0 or y_div=="":
        y_div=1
        
    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]
    selection_width = (x2-x1)*1.0
    selection_height = (y2-y1)*1.0
    
    x_offset = selection_width/x_div
    y_offset = selection_height/y_div
    
    #pdb.gimp_message(selection_width)
    #pdb.gimp_message(x_offset)
    
    
    for i in range(0, x_div+1):
        next_pos = x1 + i*x_offset
        pdb.gimp_image_add_vguide(img, next_pos)
    
    for i in range(0, y_div+1):
        next_pos = y1 + i*y_offset
        pdb.gimp_image_add_hguide(img, next_pos)
    
    pdb.gimp_image_undo_group_end(img)

    
register(
"g-divide-selection-using-guides",
"Creates guides inside of the selection",
"Divides selection using evenly spaced guides",
"Goran","Goran","2023",
"Divide selection using guides",
"*",
[
        (PF_IMAGE, "image","takes curr image", None),
        (PF_INT, "x_div", "horizontal divisions", 10),
    (PF_INT, "y_div", "vertical divisions", 10)


],
[],
divide_selection_using_guides, menu="<Image>/Image/Guides")


main()

Again thank you that's a nice script
Reply


Messages In This Thread
Divide selection using guides - by goran - 04-14-2023, 09:33 AM
RE: Divide selection using guides - by PixLab - 04-14-2023, 02:11 PM
RE: Divide selection using guides - by goran - 04-14-2023, 04:20 PM
RE: Divide selection using guides - by Ofnuts - 04-14-2023, 04:46 PM
RE: Divide selection using guides - by PixLab - 04-15-2023, 04:02 AM
RE: Divide selection using guides - by goran - 04-15-2023, 11:01 AM
RE: Divide selection using guides - by PixLab - 04-16-2023, 04:05 AM
RE: Divide selection using guides - by denzjos - 04-15-2023, 07:50 AM
RE: Divide selection using guides - by goran - 04-15-2023, 05:55 PM
RE: Divide selection using guides - by denzjos - 04-18-2023, 07:01 AM
RE: Divide selection using guides - by teapot - 04-15-2023, 11:14 PM
RE: Divide selection using guides - by goran - 04-16-2023, 06:16 AM
RE: Divide selection using guides - by Krikor - 04-18-2023, 06:09 PM
RE: Divide selection using guides - by goran - 04-18-2023, 06:53 PM
RE: Divide selection using guides - by Krikor - 04-18-2023, 07:02 PM
RE: Divide selection using guides - by goran - 04-19-2023, 06:26 AM
RE: Divide selection using guides - by PixLab - 04-19-2023, 01:41 PM
RE: Divide selection using guides - by denzjos - 04-19-2023, 08:39 AM
RE: Divide selection using guides - by goran - 04-19-2023, 11:36 AM
RE: Divide selection using guides - by Krikor - 04-19-2023, 06:18 PM

Forum Jump: