0xdb poster script: only add frames if duration exists

This commit is contained in:
rolux 2013-06-06 19:36:49 +02:00
parent a53d41d1af
commit 882de2a13a
1 changed files with 15 additions and 14 deletions

View File

@ -84,20 +84,21 @@ def render_poster(data, poster):
poster_image.putpixel((margin + x, margin + y), color) poster_image.putpixel((margin + x, margin + y), color)
# small frames # small frames
for i in range(small_frames): if duration:
position = duration * (i + 1) / (small_frames + 1) for i in range(small_frames):
small_frame_url = 'https://0xdb.org/%s/96p%f.jpg' % (id, round(position * 25) / 25) position = duration * (i + 1) / (small_frames + 1)
small_frame_image = Image.open(StringIO(ox.net.read_url(small_frame_url))) small_frame_url = 'https://0xdb.org/%s/96p%f.jpg' % (id, round(position * 25) / 25)
small_frame_image_ratio = small_frame_image.size[0] / small_frame_image.size[1] small_frame_image = Image.open(StringIO(ox.net.read_url(small_frame_url)))
if frame_ratio < frame_image_ratio: small_frame_image_ratio = small_frame_image.size[0] / small_frame_image.size[1]
small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.ANTIALIAS) if frame_ratio < frame_image_ratio:
left = int((small_frame_image.size[0] - small_frame_size[0]) / 2) small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.ANTIALIAS)
small_frame_image = small_frame_image.crop((left, 0, left + small_frame_size[0], small_frame_size[1])) left = int((small_frame_image.size[0] - small_frame_size[0]) / 2)
else: small_frame_image = small_frame_image.crop((left, 0, left + small_frame_size[0], small_frame_size[1]))
small_frame_image = small_frame_image.resize((small_frame_size[0], int(small_frame_size[0] / small_frame_image_ratio)), Image.ANTIALIAS) else:
top = int((small_frame_image.size[1] - small_frame_height) / 2) small_frame_image = small_frame_image.resize((small_frame_size[0], int(small_frame_size[0] / small_frame_image_ratio)), Image.ANTIALIAS)
small_frame_image = small_frame_image.crop((0, top, small_frame_size[0], top + small_frame_size[1])) top = int((small_frame_image.size[1] - small_frame_height) / 2)
poster_image.paste(small_frame_image, (i * small_frame_size[0], frame_size[1])) small_frame_image = small_frame_image.crop((0, top, small_frame_size[0], top + small_frame_size[1]))
poster_image.paste(small_frame_image, (i * small_frame_size[0], frame_size[1]))
# text # text
offset_top = frame_size[1] + small_frame_size[1] + margin - 8 offset_top = frame_size[1] + small_frame_size[1] + margin - 8