我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用PIL.ImageFilter.CONTOUR。
def apply_effects(image, effects): """method to apply effects to original image from list of effects """ for effect in effects: gray = ImageOps.grayscale(image) # dictionary with all the availble effects all_effects = { 'BLUR': image.filter(ImageFilter.BLUR), 'CONTOUR': image.filter(ImageFilter.CONTOUR), 'EMBOSS': image.filter(ImageFilter.EMBOSS), 'SMOOTH': image.filter(ImageFilter.SMOOTH), 'HULK': ImageOps.colorize(gray, (0, 0, 0, 0), '#00ff00'), 'FLIP': ImageOps.flip(image), 'MIRROR': ImageOps.mirror(image), 'INVERT': ImageOps.invert(image), 'SOLARIZE': ImageOps.solarize(image), 'GREYSCALE': ImageOps.grayscale(image), } phedited = all_effects[effect] image = phedited return phedited
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)