forked from sahlberg/pop-fe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme_opencv.py
165 lines (132 loc) · 4.8 KB
/
theme_opencv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
# coding: utf-8
#
# Auto theme for DOTPAINTING art
#
#
from PIL import Image, ImageDraw, ImageFont
import cv2
import io
import os
import sys
if sys.platform == 'win32':
font = 'arial.ttf'
else:
font = 'DejaVuSansMono.ttf'
def create_oilpainting_pic0(game_id, title, tmpfile):
p0 = Image.new("RGB", (250, 140), (0,0,0))
fnt = ImageFont.truetype(font, 12)
d = ImageDraw.Draw(p0)
off = 100
y = 1
t = '##############################'
ts = d.textsize(t, font=fnt)
d.text((off, y), t, font=fnt, fill=(255,128,128,255))
y = y + ts[1] + 2
strings = title.split(' - ')
for t in strings:
ts = d.textsize('#', font=fnt)
d.text((off, y), '#', font=fnt, fill=(255,128,128,255))
ts = d.textsize(t, font=fnt)
d.text((off + 11, y), t, font=fnt,
fill=(255,255,255,255))
y = y + ts[1] + 2
t = '##############################'
ts = d.textsize(t, font=fnt)
d.text((off, y), t, font=fnt, fill=(255,128,128,255))
pic0 = Image.new("RGBA", (1000, 560), (255,255,255,0))
d = ImageDraw.Draw(pic0)
for i in range(250):
for j in range(140):
p = p0.getpixel((i,j))
if p != (0,0,0):
d.ellipse([(i * 4, j * 4), (i * 4 + 3, j * 4 + 3)], fill = p)
return pic0
def create_oilpainting_pic1(game_id, icon0, tmpfile):
icon0 = icon0.resize((1000,1000), Image.Resampling.BILINEAR)
icon0.save(tmpfile, format='BMP')
img = cv2.imread(tmpfile, cv2.IMREAD_COLOR)
res = cv2.xphoto.oilPainting(img, 7, 1)
cv2.imwrite(tmpfile, res)
icon0 = Image.open(tmpfile)
pic1 = Image.new("RGB", (1920, 1080), (0,0,0))
Image.Image.paste(pic1, icon0, box=(100,0))
return pic1
def create_watercolor_pic0(game_id, title, tmpfile):
p0 = Image.new("RGB", (250, 140), (0,0,0))
fnt = ImageFont.truetype(font, 12)
d = ImageDraw.Draw(p0)
off = 100
y = 1
t = '##############################'
ts = d.textsize(t, font=fnt)
d.text((off, y), t, font=fnt, fill=(255,128,128,255))
y = y + ts[1] + 2
strings = title.split(' - ')
for t in strings:
ts = d.textsize('#', font=fnt)
d.text((off, y), '#', font=fnt, fill=(255,128,128,255))
ts = d.textsize(t, font=fnt)
d.text((off + 11, y), t, font=fnt,
fill=(255,255,255,255))
y = y + ts[1] + 2
t = '##############################'
ts = d.textsize(t, font=fnt)
d.text((off, y), t, font=fnt, fill=(255,128,128,255))
pic0 = Image.new("RGBA", (1000, 560), (255,255,255,0))
d = ImageDraw.Draw(pic0)
for i in range(250):
for j in range(140):
p = p0.getpixel((i,j))
if p != (0,0,0):
d.ellipse([(i * 4, j * 4), (i * 4 + 3, j * 4 + 3)], fill = p)
return pic0
def create_watercolor_pic1(game_id, icon0, tmpfile):
icon0 = icon0.resize((1000,1000), Image.Resampling.BILINEAR)
icon0.save(tmpfile, format='BMP')
img = cv2.imread(tmpfile, cv2.IMREAD_COLOR)
res = cv2.stylization(img, sigma_s=60, sigma_r=0.6)
cv2.imwrite(tmpfile, res)
icon0 = Image.open(tmpfile)
pic1 = Image.new("RGB", (1920, 1080), (0,0,0))
Image.Image.paste(pic1, icon0, box=(100,0))
return pic1
def create_colorsketch_pic0(game_id, title, tmpfile):
p0 = Image.new("RGB", (250, 140), (0,0,0))
fnt = ImageFont.truetype(font, 12)
d = ImageDraw.Draw(p0)
off = 100
y = 1
t = '##############################'
ts = d.textsize(t, font=fnt)
d.text((off, y), t, font=fnt, fill=(255,128,128,255))
y = y + ts[1] + 2
strings = title.split(' - ')
for t in strings:
ts = d.textsize('#', font=fnt)
d.text((off, y), '#', font=fnt, fill=(255,128,128,255))
ts = d.textsize(t, font=fnt)
d.text((off + 11, y), t, font=fnt,
fill=(255,255,255,255))
y = y + ts[1] + 2
t = '##############################'
ts = d.textsize(t, font=fnt)
d.text((off, y), t, font=fnt, fill=(255,128,128,255))
pic0 = Image.new("RGBA", (1000, 560), (255,255,255,0))
d = ImageDraw.Draw(pic0)
for i in range(250):
for j in range(140):
p = p0.getpixel((i,j))
if p != (0,0,0):
d.ellipse([(i * 4, j * 4), (i * 4 + 3, j * 4 + 3)], fill = p)
return pic0
def create_colorsketch_pic1(game_id, icon0, tmpfile):
icon0.save(tmpfile, format='BMP')
img = cv2.imread(tmpfile, cv2.IMREAD_COLOR)
grey, color = cv2.pencilSketch(img, sigma_s=150, sigma_r=0.20, shade_factor=0.02)
cv2.imwrite(tmpfile, color)
icon0 = Image.open(tmpfile)
icon0 = icon0.resize((1000,1000), Image.Resampling.NEAREST)
pic1 = Image.new("RGB", (1920, 1080), (0,0,0))
Image.Image.paste(pic1, icon0, box=(100,0))
return pic1