Skip to content

Commit 449bc7b

Browse files
Merge pull request AUTOMATIC1111#15534 from storyicon/fix-masking
Fix images do not match / Coordinate 'right' is less than 'left'
2 parents 3810413 + 71314e4 commit 449bc7b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

modules/processing.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1612,13 +1612,16 @@ def init(self, all_prompts, all_seeds, all_subseeds):
16121612
self.mask_for_overlay = image_mask
16131613
mask = image_mask.convert('L')
16141614
crop_region = masking.get_crop_region(mask, self.inpaint_full_res_padding)
1615-
crop_region = masking.expand_crop_region(crop_region, self.width, self.height, mask.width, mask.height)
1616-
x1, y1, x2, y2 = crop_region
1617-
1618-
mask = mask.crop(crop_region)
1619-
image_mask = images.resize_image(2, mask, self.width, self.height)
1620-
self.paste_to = (x1, y1, x2-x1, y2-y1)
1621-
1615+
if crop_region[0] >= crop_region[2] and crop_region[1] >= crop_region[3]:
1616+
crop_region = None
1617+
image_mask = None
1618+
self.mask_for_overlay = None
1619+
else:
1620+
crop_region = masking.expand_crop_region(crop_region, self.width, self.height, mask.width, mask.height)
1621+
x1, y1, x2, y2 = crop_region
1622+
mask = mask.crop(crop_region)
1623+
image_mask = images.resize_image(2, mask, self.width, self.height)
1624+
self.paste_to = (x1, y1, x2-x1, y2-y1)
16221625
self.extra_generation_params["Inpaint area"] = "Only masked"
16231626
self.extra_generation_params["Masked area padding"] = self.inpaint_full_res_padding
16241627
else:
@@ -1648,6 +1651,8 @@ def init(self, all_prompts, all_seeds, all_subseeds):
16481651
image = images.resize_image(self.resize_mode, image, self.width, self.height)
16491652

16501653
if image_mask is not None:
1654+
if self.mask_for_overlay.size != (image.width, image.height):
1655+
self.mask_for_overlay = images.resize_image(self.resize_mode, self.mask_for_overlay, image.width, image.height)
16511656
image_masked = Image.new('RGBa', (image.width, image.height))
16521657
image_masked.paste(image.convert("RGBA").convert("RGBa"), mask=ImageOps.invert(self.mask_for_overlay.convert('L')))
16531658

0 commit comments

Comments
 (0)