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