Python PIL.ImageChops 模块,multiply() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用PIL.ImageChops.multiply()

项目:MiniTWOW-Tools    作者:hanss314    | 项目源码 | 文件源码
def make_book(name,dir):
    orig = name
    if len(name)<2:
        name += name

    left = Image.open('./resources/left.png').convert('RGBA')
    right = Image.open('./resources/right.png').convert('RGBA')
    face = Image.open('./resources/face.png').convert('RGBA')

    left = ImageChops.multiply(left, Image.new('HSV', left.size, makeLetterTint(name[0])).convert('RGBA'))
    right = ImageChops.multiply(right, Image.new('HSV', right.size, makeLetterTint(name[1])).convert('RGBA'))

    left.paste(right,(0,0),right)
    left.paste(face,(0,0),face)

    left.save('{}/{}.png'.format(dir,orig))
项目:TWOWBot    作者:Noahkiq    | 项目源码 | 文件源码
def make_book(name,dir):
    orig = name
    if len(name)<2:
        name += name

    left = Image.open('./resources/left.png').convert('RGBA')
    right = Image.open('./resources/right.png').convert('RGBA')
    face = Image.open('./resources/face.png').convert('RGBA')

    left = ImageChops.multiply(left, Image.new('HSV', left.size, makeLetterTint(name[0])).convert('RGBA'))
    right = ImageChops.multiply(right, Image.new('HSV', right.size, makeLetterTint(name[1])).convert('RGBA'))

    left.paste(right,(0,0),right)
    left.paste(face,(0,0),face)

    left.save('{}/{}.png'.format(dir,orig))
项目:ascii-art-py    作者:blinglnav    | 项目源码 | 文件源码
def do_multiply(self):
        """usage: multiply <image:pic1> <image:pic2>

        Pop the two top images, push the multiplication image.
        """
        from PIL import ImageChops
        image1 = self.do_pop()
        image2 = self.do_pop()
        self.push(ImageChops.multiply(image1, image2))
项目:pudzu    作者:Udzu    | 项目源码 | 文件源码
def add_shadow(self, color="black", blur=2, offset=(0,0), resize=True, shadow_only=False):
        """Add a drop shadow to an image"""
        if not self.mode.endswith('A'): return self
        shadow = Image.from_pattern(color, self.size) if isinstance(color, Image.Image) else Image.new("RGBA", self.size, color)
        shadow.putalpha(ImageChops.multiply(self.split()[-1], shadow.split()[-1]))
        shadow = shadow.pad(blur, 0)
        if blur: shadow = shadow.filter(ImageFilter.GaussianBlur(blur))
        offsets = Padding(0)
        img = Image.new("RGBA", self.size, 0)
        img = img.pin(shadow, (offset[0]-blur,offset[1]-blur), align=0, offsets=offsets)
        if not shadow_only: img = img.pin(self, (0,0), align=0, offsets=offsets)
        if not resize: img = img.crop((offsets[0], offsets[1], img.width-offsets[2], img.height-offsets[3]))
        return img
项目:maze-builder    作者:kcsaff    | 项目源码 | 文件源码
def __init__(self, width, height, illustrators, fun=ImageChops.multiply):
        self.width = width
        self.height = height
        self.illustrators = illustrators
        if isinstance(fun, str):
            fun = getattr(ImageChops, fun)
        self.fun = fun
项目:PoiBot    作者:link2110    | 项目源码 | 文件源码
def rip(self, ctx, member_or_text: str):
        """RIP\nCreates a tombstone for either a member or some text. Mention a member to get the avatar + name"""
        if ctx.message.mentions:
            user_name = ctx.message.mentions[0].name.replace(" ", "%20")
            rip_member = ctx.message.mentions[0]
            ava_url = rip_member.avatar_url
            url = "https://ripme.xyz/{}"
            msg = url.format(user_name)

            tomb = Image.open(os.path.join(asset_pos, "tombstone.png"))
            base_img = Image.new("RGBA", (tomb.width, tomb.height), color="White")
            with aiohttp.ClientSession() as session:
                async with session.get(ava_url) as resp:
                    ava = await resp.content.read()

            ava_img = Image.open(io.BytesIO(ava))
            ava_img_greyscale = ImageOps.autocontrast(ava_img.convert("L").filter(ImageFilter.CONTOUR)).filter(
                ImageFilter.SMOOTH).resize((200, 200))
            base_img.paste(ava_img_greyscale, (140, 380, 340, 580))
            final = ImageChops.multiply(base_img, tomb)
            f = ImageFont.truetype(os.path.join(asset_pos, "Symbola.ttf"), size=35)
            d = ImageDraw.Draw(final)
            w, h = d.textsize(rip_member.name, font=f)
            d.multiline_text(((60 + ((350 - w) / 2)), 315), rip_member.name, fill="Black", font=f, align="center")
            final.save(os.path.join(asset_pos, "rip.png"))
            await self.bot.send_file(ctx.message.channel, os.path.join(asset_pos, "rip.png"), content=msg)
        else:
            content = ctx.message.content.partition(" ")
            user_name = content[2].replace(" ", "_")
            url = "https://ripme.xyz/{}"
            msg = url.format(user_name)
            base_img = Image.new("RGB", (520, 640), color="White")
            tomb = Image.open(os.path.join(asset_pos, "tombstone.png"))
            base_img.paste(tomb)
            f = ImageFont.truetype(os.path.join(asset_pos, "Symbola.ttf"), size=35)
            d = ImageDraw.Draw(base_img)
            text = textwrap.shorten(content[2], width=25, placeholder="")
            w, h = d.textsize(text, font=f)
            d.text(((60 + ((350 - w) / 2)), 315), text, fill="Black", font=f, align="center")
            d.text((160, 450), "2016 - 2016", fill="Black", font=f)
            base_img.save(os.path.join(asset_pos, "rip.jpeg"))
            await self.bot.send_file(ctx.message.channel, os.path.join(asset_pos, "rip.jpeg"), content=msg)