我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用PIL.ImageFilter.FIND_EDGES。
def main(): if not os.path.exists('emoji'): os.mkdir('emoji') font = ImageFont.truetype('kimberley bl.ttf', 128) for stat, bits in stat_ranges.items(): numbers, colour = bits for number in numbers: im = Image.new("RGBA", (300, 300), (255, 255, 255, 0)) draw = ImageDraw.Draw(im) draw.text((0, 0), number, font=font, fill=colour) # remove unneccessory whitespaces if needed im = im.crop(ImageOps.invert(im.convert('RGB')).getbbox()) # im = ImageOps.invert(im) im.thumbnail(size, Image.ANTIALIAS) background = Image.new('RGBA', size, (255, 255, 255, 0)) background.paste( im, ((size[0] - im.size[0]) // 2, (size[1] - im.size[1]) // 2)) # background.paste( # im.filter(ImageFilter.FIND_EDGES).convert('1'), # ((size[0] - im.size[0]) // 2, (size[1] - im.size[1]) // 2)) # write into file number = number.replace('±', '_') number = number.replace('+', 'plus') background.save("emoji/{}.png".format('{}{}'.format(stat, number)))
def findedges(message, im): """ Applies a find-edges effect. Example:: /drawtext Hello there! | find edges Requires an input image. """ return im.filter(ImageFilter.FIND_EDGES)