Let the text-to-mask .mask.png file be used as a mask

Ironically, the black and white mask file generated by the
`invoke> !mask` command could not be passed as the mask to
`img2img`. This is now fixed and the documentation updated.
This commit is contained in:
Lincoln Stein
2022-10-22 13:53:23 -04:00
parent d8c1b78d83
commit 2e14ba8716
2 changed files with 23 additions and 10 deletions

View File

@ -911,9 +911,12 @@ class Generate:
# with alpha transparency. It converts it into a black/white
# image with the transparent part black.
def _image_to_mask(self, mask_image, invert=False) -> Image:
# Obtain the mask from the transparency channel
mask = Image.new(mode="L", size=mask_image.size, color=255)
mask.putdata(mask_image.getdata(band=3))
if mask_image.mode in ('L','RGB'):
mask = mask_image
else:
# Obtain the mask from the transparency channel
mask = Image.new(mode="L", size=mask_image.size, color=255)
mask.putdata(mask_image.getdata(band=3))
if invert:
mask = ImageOps.invert(mask)
return mask