Example #1
0
    def setup(self):
        for st in self._imgs:
            w, h = self.pos['width'], self.pos['height']
            x = (w - self._img_source.size[0]) / 2
            y = (h - self._img_source.size[1]) / 2

            buttonbg = image.hex_to_rgb(self.frame.colors[st]['buttonbg'])
            buttonfg = image.hex_to_rgb(self.frame.colors[st]['buttonfg'])

            # Create the "base" image
            normal = Image.new('RGBA', (w, h), color=buttonbg)
            normal.paste(self._img_source, box=(x, y), mask=self._img_source)

            imgd = ImageDraw.Draw(normal)
            imgd.bitmap((x, y), self._img_source, fill=buttonfg)

            # Make other two states before beveling
            hover = normal.copy()
            click = normal.copy()

            # Now add effects that differentiate the states
            rendering.bevel_up(normal)

            bright = ImageEnhance.Brightness(click)
            click = bright.enhance(1.2)
            rendering.bevel_down(click)

            bright = ImageEnhance.Brightness(hover)
            hover = bright.enhance(1.2)
            rendering.bevel_up(hover)

            self._imgs[st]['normal'] = image.get_data(normal)
            self._imgs[st]['click'] = image.get_data(click)
            self._imgs[st]['hover'] = image.get_data(hover)
Example #2
0
def border(border_color, bg_color, width, height, orient):
    assert ((width == 1 and orient in ('top', 'bottom')) or
            (height == 1 and orient in ('left', 'right')))

    im = Image.new('RGBA', (width, height))
    bg = (max(width, height) - 1) * [image.hex_to_rgb(bg_color)]
    border = [image.hex_to_rgb(border_color)]

    if orient in ('bottom', 'right'):
        data = bg + border
    else:
        data = border + bg

    im.putdata(data)

    return im
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