new poster

This commit is contained in:
Jan Gerber 2015-09-20 18:27:24 +01:00
parent 5821a4d5eb
commit 76d11edb68

39
scripts/poster.py Executable file → Normal file
View file

@ -52,7 +52,6 @@ def render_poster(data, poster):
year = str(data.get('year', ''))
collection = data.get('collection', '')
duration = data.get('duration')
oxdb_id = data['oxdbId']
id = data['id']
frame = data.get('frame')
timeline = data.get('timeline')
@ -60,7 +59,7 @@ def render_poster(data, poster):
poster_size = (640, 1024)
frame_size = (640, 480)
frame_ratio = frame_size[0] / frame_size[1]
logo_size = (64, 32)
logo_size = (32, 32)
small_frames = 8
small_frame_size = (80, 64)
small_frame_ratio = small_frame_size[0] / small_frame_size[1]
@ -69,10 +68,15 @@ def render_poster(data, poster):
font_size_small = 32
font_size_large = 48
font_file = os.path.join(static_root, 'MontserratBold.ttf')
hue = int(oxdb_id[2:10], 16) / pow(2, 32) * 360
image_color = getRGB([hue, 1, 0.2])
background_color = getRGB([hue, 1, 0.4])
foreground_color = getRGB([hue, 1, 0.8])
if collection:
hue = get_hue(collection, title)
saturation = 1
else:
hue = 0
saturation = 0
image_color = getRGB([hue, saturation, 0.2])
background_color = getRGB([hue, saturation, 0.4])
foreground_color = getRGB([hue, saturation, 0.8])
poster_image = Image.new('RGB', poster_size)
draw = ImageDraw.Draw(poster_image)
@ -93,16 +97,9 @@ def render_poster(data, poster):
draw.rectangle(((0, 0), frame_size), fill=image_color)
# logo
logo_image = Image.open(os.path.join(static_root, 'logo.maydayrooms.png'))
logo_image = Image.open(os.path.join('/srv/pandora/static/png/', 'logo.png'))
logo_image = logo_image.resize(logo_size, Image.ANTIALIAS)
for y in range(logo_size[1]):
for x in range(logo_size[0]):
poster_color = poster_image.getpixel((margin + x, margin + y))
logo_lightness = logo_image.getpixel((x, y))[0] / 255
logo_alpha = logo_image.getpixel((x, y))[3] / 255
logo_color = getRGB([hue, 1, logo_lightness])
color = tuple([int(logo_color[i] * logo_alpha + poster_color[i] * (1 - logo_alpha)) for i in range(3)])
poster_image.putpixel((margin + x, margin + y), color)
poster_image.paste(logo_image, (margin, margin), mask=logo_image.split()[3])
# small frames
if duration:
@ -179,25 +176,25 @@ def render_poster(data, poster):
)
offset_top += font_size_small
# year
if year:
# id
drawText(
poster_image,
(margin, poster_size[1] - timeline_size[1] - margin - font_size_large),
year,
id,
font_file,
font_size_large,
foreground_color
)
# id
# year
if year:
drawText(
poster_image,
(
poster_size[0] - margin - getTextSize(poster_image, id, font_file, font_size_small)[0],
poster_size[0] - margin - getTextSize(poster_image, year, font_file, font_size_small)[0],
poster_size[1] - timeline_size[1] - margin - font_size_small
),
id,
year,
font_file,
font_size_small,
foreground_color