1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import os
23
24 __version__ = "$Rev: 6125 $"
25
26 directory = os.path.split(os.path.abspath(__file__))[0]
27 fontpath = os.path.join(directory, 'Vera.ttf')
28 logopath = directory
29
30 fluendoLogoPath = os.path.join(logopath, 'fluendo.36x36.png')
31 ccLogoPath = os.path.join(logopath, 'cc.36x36.png')
32 xiphLogoPath = os.path.join(logopath, 'xiph.36x36.png')
33
34 TEXT_XOFFSET = 6
35 TEXT_YOFFSET = 6
36 WIDTH = 36
37 BORDER = 8
38 FONT_SIZE = 22
39
40 -def generate_overlay(filename, text, show_fluendo, show_cc, show_xiph,
41 width, height):
42 from PIL import Image
43 from PIL import ImageChops
44 from PIL import ImageDraw
45 from PIL import ImageFont
46 from PIL import ImageOps
47
48 image = Image.new("RGBA", (width, height))
49 draw = ImageDraw.Draw(image)
50
51 if text:
52 font = ImageFont.truetype(fontpath, FONT_SIZE)
53 draw.text((TEXT_XOFFSET+2, TEXT_YOFFSET+2),
54 text, font=font, fill='black')
55 draw.text((TEXT_XOFFSET, TEXT_YOFFSET),
56 text, font=font)
57
58
59 logos = len([i for i in (show_fluendo, show_cc, show_xiph) if i]) - 1
60
61
62
63
64
65 imax = max(width, height)
66 y_corr = -(abs(width - height) + WIDTH + BORDER)
67
68 if show_xiph:
69 xiph = Image.open(xiphLogoPath)
70 xiph = ImageOps.expand(xiph, imax)
71 xiph = ImageChops.offset(xiph, -width + (WIDTH*logos), y_corr)
72 image = ImageChops.add_modulo(image, xiph)
73 logos -= 1
74
75 if show_cc:
76 cc = Image.open(ccLogoPath)
77 cc = ImageOps.expand(cc, imax)
78 cc = ImageChops.offset(cc, -width + (WIDTH*logos), y_corr)
79 image = ImageChops.add_modulo(image, cc)
80 logos -= 1
81
82 if show_fluendo:
83 fluendo = Image.open(fluendoLogoPath)
84 fluendo = ImageOps.expand(fluendo, imax)
85 fluendo = ImageChops.offset(fluendo, -width, y_corr)
86 image = ImageChops.add_modulo(image, fluendo)
87
88 if os.path.exists(filename):
89 os.unlink(filename)
90
91 image.save(filename, 'png')
92
93 if text:
94 return (draw.textsize(text, font=font)[0] + TEXT_XOFFSET > width)
95 else:
96 return False
97
98 if __name__ == '__main__':
99
100 generate_overlay('test.png', 'Testing', True, True, True, 320, 240)
101