

def do_mask(img, mask_path, mask_source, mask_mode=None):
    if (not mask_path):
        return img
    if (mask_source == 'media'):
        mask = pil.open(MEDIA_STORAGE.open(ow)).convert('RGBA')
    else:
        mask = pil.open(STATIC_STORAGE.open(mask_path)).convert('RGBA')
    if (mask_mode == 'distort'):
        (iw, ih) = img.size
        (mw, mh) = mask.size
        if ((mw != iw) or (mh != ih)):
            mask = mask.resize((iw, ih), pil.ANTIALIAS)
    else:
        (iw, ih) = img.size
        (ow, oh) = mask.size
        overlay_ratio = (float(ow) / float(oh))
        have_to_scale = False
        if (ow > iw):
            ow = iw
            oh = int((float(iw) / overlay_ratio))
        if (oh > ih):
            ow = int((float(ih) * overlay_ratio))
            oh = ih
        if ((ow != iw) or (oh != ih)):
            have_to_scale = True
        if have_to_scale:
            nmask = mask.resize((ow, oh), pil.ANTIALIAS)
            mask = pil.new('RGBA', (iw, ih))
            do_paste(mask, nmask, (int(((iw - ow) / 2)), int(((ih - oh) / 2))))
            (ow, oh) = mask.size
    (r, g, b, a) = mask.split()
    img.putalpha(a)

dataset/ETHPy150Open francescortiz/image/image/utils.py do_mask/VarMisuse@49/68 `mask_path`->`ow`