fnp
/
audio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Genre- and collection-specific thumbnails.
[audio.git]
/
src
/
youtube
/
thumbnail.py
diff --git
a/src/youtube/thumbnail.py
b/src/youtube/thumbnail.py
index
42e8070
..
8eb7973
100644
(file)
--- a/
src/youtube/thumbnail.py
+++ b/
src/youtube/thumbnail.py
@@
-2,12
+2,6
@@
import yaml
from PIL import Image, ImageDraw, ImageFont
from PIL import Image, ImageDraw, ImageFont
-def drawbox(img, d, context, get_font_path):
- for version in d['versions']:
- if draw_version(img, version, context, get_font_path):
- break
-
-
def split_to_lines(text, draw, font, max_width):
words = text.split()
current = ''
def split_to_lines(text, draw, font, max_width):
words = text.split()
current = ''
@@
-28,8
+22,7
@@
def split_to_lines(text, draw, font, max_width):
yield current
yield current
-def draw_version(img, d, context, get_font_path):
- # todo: do this in a subimg
+def draw_box(img, d, context, get_font_path):
newimg = Image.new(
'RGBA',
(
newimg = Image.new(
'RGBA',
(
@@
-48,7
+41,11
@@
def draw_version(img, d, context, get_font_path):
continue
if item.get('uppercase'):
text = text.upper()
continue
if item.get('uppercase'):
text = text.upper()
- font = ImageFont.truetype(get_font_path(item['font-family']), item['font-size'])
+ font = ImageFont.truetype(
+ get_font_path(item['font-family']),
+ item['font-size'],
+ layout_engine=ImageFont.LAYOUT_BASIC
+ )
max_width = item.get('max-width', newimg.size[0])
for line in split_to_lines(text, draw, font, max_width):
max_width = item.get('max-width', newimg.size[0])
for line in split_to_lines(text, draw, font, max_width):
@@
-66,5
+63,6
@@
def create_thumbnail(background_path, defn, context, get_font_path):
img = Image.open(background_path)
d = yaml.load(defn)
for boxdef in d['boxes']:
img = Image.open(background_path)
d = yaml.load(defn)
for boxdef in d['boxes']:
- drawbox(img, boxdef, context, get_font_path)
+ if not draw_box(img, boxdef, context, get_font_path):
+ raise ValueError()
return img
return img