use box for inoutpaint
parent
90ec2efc97
commit
52e38efc90
|
|
@ -13,25 +13,27 @@ except:
|
|||
HTML_TEMPLATES = {"resolution": """<textarea>"""}
|
||||
|
||||
|
||||
def run(img, u, d, l, r, mode="fill"):
|
||||
def run(img, w, h, t, b, l, r, mode="fill"):
|
||||
w, h, t, b, l, r = int(w), int(h), int(t), int(b), int(l), int(r)
|
||||
|
||||
img = img.resize((r-l, b-t))
|
||||
new_img, mask = resize_with_mask(
|
||||
img,
|
||||
(u, d, l, r),
|
||||
img, w, h, t, b, l, r
|
||||
)
|
||||
|
||||
w, h = img.size
|
||||
w_n, h_n = new_img.size
|
||||
|
||||
if u:
|
||||
new_img.paste(img.resize((w, u), box=(0, 0, w, 0)), box=(l, 0))
|
||||
if d:
|
||||
new_img.paste(img.resize((w, d), box=(0, h, w, h)), box=(l, u + h))
|
||||
if t:
|
||||
new_img.paste(img.resize((w, t), box=(0, 0, w, 0)), box=(l, 0))
|
||||
if b<h_n:
|
||||
new_img.paste(img.resize((w, h_n-b), box=(0, h, w, h)), box=(l, b))
|
||||
|
||||
if l:
|
||||
new_img.paste(new_img.resize((l, h_n), box=(l + 1, 0, l + 1, h_n)), box=(0, 0))
|
||||
if r:
|
||||
if r<w_n:
|
||||
new_img.paste(
|
||||
new_img.resize((r, h_n), box=(w + l - 1, 0, w + l - 1, h_n)), box=(l + w, 0)
|
||||
new_img.resize((w_n-r, h_n), box=(w + l - 1, 0, w + l - 1, h_n)), box=(l + w, 0)
|
||||
)
|
||||
|
||||
return new_img, mask, f"{w_n} x {h_n}"
|
||||
|
|
|
|||
|
|
@ -6,15 +6,12 @@ from PIL import Image
|
|||
|
||||
|
||||
def resize_with_mask(
|
||||
img: Image.Image, expands: tuple[int, int, int, int]
|
||||
img: Image.Image, w, h, t, b, l, r,
|
||||
) -> tuple[Image.Image, Image.Image]:
|
||||
w, h = img.size
|
||||
u, d, l, r = expands
|
||||
new_img = Image.new("RGB", (w, h))
|
||||
new_img.paste(img, (l, t))
|
||||
|
||||
new_img = Image.new("RGB", (w + l + r, h + u + d))
|
||||
new_img.paste(img, (l, u))
|
||||
|
||||
mask = Image.new("L", (w + l + r, h + u + d), 255)
|
||||
mask_none = Image.new("L", (w, h), 0)
|
||||
mask.paste(mask_none, (l, u))
|
||||
mask = Image.new("L", (w, h), 255)
|
||||
mask_none = Image.new("L", (r-l, b-t), 0)
|
||||
mask.paste(mask_none, (l, t))
|
||||
return new_img, mask
|
||||
|
|
|
|||
|
|
@ -357,12 +357,30 @@ def add_tab():
|
|||
)
|
||||
with gr.Tabs(elem_id="function list"):
|
||||
with gr.TabItem("InOutPaint"):
|
||||
iop_u = gr.Slider(0, 512, 0, step=64, label="fill up")
|
||||
iop_d = gr.Slider(0, 512, 0, step=64, label="fill down")
|
||||
iop_l = gr.Slider(0, 512, 0, step=64, label="fill left")
|
||||
iop_r = gr.Slider(
|
||||
0, 512, 0, step=64, label="fill right"
|
||||
)
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
iop_width = gr.Number(
|
||||
value=512, label="output width"
|
||||
)
|
||||
with gr.Column():
|
||||
iop_height = gr.Number(
|
||||
value=512, label="output Height"
|
||||
)
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
iop_align_top = gr.Number(
|
||||
value=0, label="align top"
|
||||
)
|
||||
iop_align_left = gr.Number(
|
||||
value=0, label="align left"
|
||||
)
|
||||
with gr.Column():
|
||||
iop_align_bottom = gr.Number(
|
||||
value=512, label="align bottom"
|
||||
)
|
||||
iop_align_right = gr.Number(
|
||||
value=512, label="align right"
|
||||
)
|
||||
iop_btn = gr.Button("refresh", variant="primary")
|
||||
with gr.TabItem("Flip"):
|
||||
flip_axis = gr.Radio(
|
||||
|
|
@ -546,7 +564,14 @@ def add_tab():
|
|||
tilt_shift_btn.click(tilt_shift.run, input_, image_out)
|
||||
|
||||
# iop
|
||||
all_iop_set = [iop_u, iop_d, iop_l, iop_r]
|
||||
all_iop_set = [
|
||||
iop_width,
|
||||
iop_height,
|
||||
iop_align_top,
|
||||
iop_align_bottom,
|
||||
iop_align_left,
|
||||
iop_align_right,
|
||||
]
|
||||
all_iop_input = [image_other] + all_iop_set
|
||||
for component in all_iop_set:
|
||||
_release_if_possible(
|
||||
|
|
|
|||
Loading…
Reference in New Issue