Skip to content

Commit

Permalink
Merge pull request #337 from Dutch77/feature/base64-mask-image-support
Browse files Browse the repository at this point in the history
feat:  base64 mask image support
  • Loading branch information
hako-mikan authored Sep 29, 2024
2 parents 781ff1d + f43784a commit 3c3c4bc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/rp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
create_canvas, draw_region, #detect_mask, detect_polygons,
draw_image, save_mask, load_mask, changecs,
floatdef, inpaintmaskdealer, makeimgtmp, matrixdealer)
from io import BytesIO
import base64

KEYBRK_R = "RP_TEMP_REPLACE"
FLJSON = "regional_prompter_presets.json"
Expand Down Expand Up @@ -400,10 +402,18 @@ def process(self, p, active, a_debug , rp_selected_tab, mmode, xmode, pmode, ara
self.slowlora = OPTUSEL in options

if type(polymask) == str:
image = None
try:
polymask,_,_ = draw_image(np.array(Image.open(polymask)))
image = Image.open(polymask)
except:
pass
if polymask.startswith("data:image/"):
polymask = polymask.split(";", maxsplit=1)[1].split(",", maxsplit=1)[1]
try:
image = Image.open(BytesIO(base64.b64decode(polymask)))
except:
print("Error: The mask image is either not a valid path or not a valid base64 encoded image.")
if image is not None:
polymask,_,_ = draw_image(np.array(image.convert('RGB')))

if rp_selected_tab == "Nope": rp_selected_tab = "Matrix"

Expand Down

0 comments on commit 3c3c4bc

Please sign in to comment.