コード例 #1
0
ファイル: colorutils.py プロジェクト: qiaohui/pygaga
def colors_as_image(colors):
    "Save palette as a PNG with labeled, colored blocks"
    colors = [hex_to_rgb("#%s" % c) for c in colors]
    size = (80 * len(colors), 80)
    im = Image.new('RGB', size)
    draw = ImageDraw.Draw(im)
    for i, c in enumerate(colors):
        v = colorsys.rgb_to_hsv(*norm_color(c))[2]
        (x1, y1) = (i * 80, 0)
        (x2, y2) = ((i + 1) * 80 - 1, 79)
        draw.rectangle([(x1, y1), (x2, y2)], fill=c)
        if v < 0.6:
            # white with shadow
            draw.text((x1 + 4, y1 + 4), rgb_to_hex(c), (90, 90, 90))
            draw.text((x1 + 3, y1 + 3), rgb_to_hex(c))
        else:
            # dark with bright "shadow"
            draw.text((x1 + 4, y1 + 4), rgb_to_hex(c), (230, 230, 230))
            draw.text((x1 + 3, y1 + 3), rgb_to_hex(c), (0, 0, 0))
    return im
コード例 #2
0
ファイル: colorutils.py プロジェクト: qiaohui/pygaga
def colors_as_image(colors):
    "Save palette as a PNG with labeled, colored blocks"
    colors = [hex_to_rgb("#%s" % c) for c in colors]
    size = (80 * len(colors), 80)
    im = Image.new('RGB', size)
    draw = ImageDraw.Draw(im)
    for i, c in enumerate(colors):
        v = colorsys.rgb_to_hsv(*norm_color(c))[2]
        (x1, y1) = (i * 80, 0)
        (x2, y2) = ((i + 1) * 80 - 1, 79)
        draw.rectangle([(x1, y1), (x2, y2)], fill=c)
        if v < 0.6:
            # white with shadow
            draw.text((x1 + 4, y1 + 4), rgb_to_hex(c), (90, 90, 90))
            draw.text((x1 + 3, y1 + 3), rgb_to_hex(c))
        else:
            # dark with bright "shadow"
            draw.text((x1 + 4, y1 + 4), rgb_to_hex(c), (230, 230, 230))
            draw.text((x1 + 3, y1 + 3), rgb_to_hex(c), (0, 0, 0))
    return im
コード例 #3
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def distance(self, c1, c2):
     return colorific.distance(
         colorific.hex_to_rgb(c1),
         colorific.hex_to_rgb(c2),
     )
コード例 #4
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def test_hex_to_rgb(self):
     for rgb, hexval in self.pairs:
         self.assertEqual(colorific.hex_to_rgb(hexval), rgb)
コード例 #5
0
 def distance(self, c1, c2):
     return colorific.distance(
         colorific.hex_to_rgb(c1),
         colorific.hex_to_rgb(c2),
     )
コード例 #6
0
 def test_hex_to_rgb(self):
     for rgb, hexval in self.pairs:
         self.assertEqual(colorific.hex_to_rgb(hexval), rgb)