Example #1
0
def draw_text_bgcolor(font, text, color_bg, color_text, max_width, max_height):
    fw, fh = get_text_extents(font, text)

    w, h = min(fw, max_width), min(fh, max_height)

    im = Image.new('RGBA', (w, h), color=image.color_humanize(color_bg))
    d = ImageDraw.Draw(im)
    d.text((0, 0), unicode(text, 'utf-8'), font=font,
           fill=image.color_humanize(color_text))

    return im
Example #2
0
def blend(img, mask, color, width, height, alpha=1):
    assert width > 0 and height > 0

    bg = Image.new('RGBA', (width, height), color=image.color_humanize(color))
    blended = Image.composite(img, bg, mask)

    if alpha != 1:
        bg2 = bg.copy()
        blended = Image.blend(bg2, blended, alpha)

    return blended
Example #3
0
def corner(border_color, bg_color, width, height, orient):
    im = Image.new('RGBA', (width, height), color=image.color_humanize(bg_color))
    d = ImageDraw.Draw(im)

    coords = None

    w, h = width, height
    if orient in ('top_left', 'left_top'):
        coords = [(0, h), (0, 0), (w, 0)]
    elif orient in ('top_right', 'right_top'):
        coords = [(0, 0), (w - 1, 0), (w - 1, h)]
    elif orient in ('right_bottom', 'bottom_right'):
        coords = [(w - 1, 0), (w - 1, h - 1), (0, h - 1)]
    elif orient in ('bottom_left', 'left_bottom'):
        coords = [(0, 0), (0, h - 1), (w - 1, h - 1)]

    assert coords is not None

    d.line(coords, fill=image.hex_to_rgb(border_color))

    return im
Example #4
0
def box(color, width, height):
    im = Image.new('RGBA', (width, height), color=image.color_humanize(color))

    return im