Exemplo n.º 1
0
def text_surface(text, size, font, color, outline_color=None):
    """
    :return pygame.Surface, tuple(width, height):
    """
    image_font = ImageFont.truetype(font, size)
    image_width, image_height = image_font.getsize(text)
    image = create_blank_image(image_width, image_height)
    draw = ImageDraw.Draw(image)
    if outline_color:
        draw.text((0, 0), text, hex2rgba(outline_color), font=image_font)
        image = image.filter(ImageFilter.GaussianBlur(1))
        draw = ImageDraw.Draw(image)
    draw.text((0, 0), text, hex2rgba(color), font=image_font)
    return from_pil_to_pygame(image), (image_width, image_height)
Exemplo n.º 2
0
def text_surface(text, size, font, color, outline_color=None):
    """
    :return pygame.Surface, tuple(width, height):
    """
    image_font = ImageFont.truetype(font, size)
    image_width, image_height = image_font.getsize(text)
    image = create_blank_image(image_width, image_height)
    draw = ImageDraw.Draw(image)
    if outline_color:
        draw.text((0, 0), text, hex2rgba(outline_color), font=image_font)
        image = image.filter(ImageFilter.GaussianBlur(1))
        draw = ImageDraw.Draw(image)
    draw.text((0, 0), text, hex2rgba(color), font=image_font)
    return from_pil_to_pygame(image), (image_width, image_height)
Exemplo n.º 3
0
def normalize(image):
    image = image.filter(ImageFilter.BLUR)
    picture = ImageChops.blend(ImageOps.equalize(image), image, .5)
    return ImageChops.multiply(picture, picture)
Exemplo n.º 4
0
def normalize(image):
    image = image.filter(ImageFilter.BLUR)
    picture = ImageChops.blend(ImageOps.equalize(image), image, .5)
    return ImageChops.multiply(picture, picture)
Exemplo n.º 5
0
def rndColor2():
    return (random.randint(32,
                           127), random.randint(32,
                                                127), random.randint(32, 127))


#图片大小240*60:
width = 60 * 4
height = 60
image = Image.new('RGB', (width, height), (155, 155, 155))

#创建Font对象:
font = ImageFont.truetype('C:\Windows\Fonts\Arial.ttf', 36)

#创建Draw对象:
draw = ImageDraw.Draw(image)

#填充每个像素:
for x in range(width):
    for y in range(height):
        draw.point((x, y), fill=rndColor1())

#输出文字:
for i in range(4):
    draw.text((60 * i + 10, 10), rndChar(), fill=rndColor2(), font=font)

#模糊处理:
image = image.filter(ImageFilter.BLUR)
image.save('test.jpg', 'jpeg')
print('生成成功!')