2017-11-02 21:08:17 +00:00
|
|
|
#!/usr/bin/env python3
|
2010-10-16 11:49:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-11-30 17:29:33 +00:00
|
|
|
import os
|
2018-01-18 09:58:18 +00:00
|
|
|
import sys
|
2010-11-30 17:29:33 +00:00
|
|
|
|
2016-06-25 18:36:20 +00:00
|
|
|
from PIL import Image
|
2010-10-16 11:49:45 +00:00
|
|
|
from optparse import OptionParser
|
|
|
|
|
2017-11-02 21:08:17 +00:00
|
|
|
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
2011-10-27 22:15:37 +00:00
|
|
|
static_root = os.path.join(os.path.dirname(__file__), 'data')
|
2010-10-16 11:49:45 +00:00
|
|
|
|
2017-11-02 21:08:17 +00:00
|
|
|
|
2010-10-16 11:49:45 +00:00
|
|
|
def render_icon(frame, timeline, icon):
|
2011-08-07 18:30:14 +00:00
|
|
|
icon_width = 1024
|
|
|
|
icon_height = 1024
|
2011-08-06 14:14:22 +00:00
|
|
|
icon_image = Image.new('RGBA', (icon_width, icon_height), (0, 0, 0, 0))
|
2010-10-16 11:49:45 +00:00
|
|
|
frame_width = icon_width
|
2011-08-07 18:30:14 +00:00
|
|
|
frame_ratio = 1
|
2010-10-16 11:49:45 +00:00
|
|
|
frame_height = int(round(frame_width / frame_ratio))
|
2011-08-07 18:30:14 +00:00
|
|
|
frame_image = Image.open(frame) if frame else Image.new('RGB', (1024, 768), (0, 0, 0))
|
2010-10-16 11:49:45 +00:00
|
|
|
frame_image_ratio = frame_image.size[0] / frame_image.size[1]
|
|
|
|
if frame_ratio < frame_image_ratio:
|
|
|
|
frame_image = frame_image.resize((int(frame_height * frame_image_ratio), frame_height), Image.ANTIALIAS)
|
|
|
|
left = int((frame_image.size[0] - frame_width) / 2)
|
|
|
|
frame_image = frame_image.crop((left, 0, left + frame_width, frame_height))
|
|
|
|
else:
|
|
|
|
frame_image = frame_image.resize((frame_width, int(frame_width / frame_image_ratio)), Image.ANTIALIAS)
|
|
|
|
top = int((frame_image.size[1] - frame_height) / 2)
|
|
|
|
frame_image = frame_image.crop((0, top, frame_width, top + frame_height))
|
2011-08-06 14:42:10 +00:00
|
|
|
icon_image.paste(frame_image, (0, 0))
|
2011-08-07 18:30:14 +00:00
|
|
|
timeline_left = 64
|
|
|
|
timeline_top = 832
|
|
|
|
timeline_width = 896
|
|
|
|
timeline_height = 128
|
|
|
|
timeline_image = Image.new('RGB', (timeline_width + 8, timeline_height + 8), (255, 255, 255))
|
2011-10-27 23:16:43 +00:00
|
|
|
mask_image = Image.open(os.path.join(static_root, 'iconTimelineOuterMask.png'))
|
2011-08-07 18:30:14 +00:00
|
|
|
icon_image.paste(timeline_image, (timeline_left - 4, timeline_top - 4), mask=mask_image)
|
|
|
|
timeline_image = Image.open(timeline) if timeline else Image.new('RGB', (timeline_width, timeline_height), (0, 0, 0))
|
|
|
|
timeline_image = timeline_image.resize((timeline_width, timeline_height), Image.ANTIALIAS)
|
2011-10-27 23:16:43 +00:00
|
|
|
mask_image = Image.open(os.path.join(static_root, 'iconTimelineInnerMask.png'))
|
2011-08-07 18:30:14 +00:00
|
|
|
icon_image.paste(timeline_image, (timeline_left, timeline_top), mask=mask_image)
|
2011-08-06 14:42:10 +00:00
|
|
|
# we're using jpegs with border-radius
|
2011-10-27 23:16:43 +00:00
|
|
|
# mask_image = Image.open(os.path.join(static_root, 'iconMask.png'))
|
2011-08-06 14:42:10 +00:00
|
|
|
# icon_image.putalpha(mask_image)
|
2018-01-18 09:58:18 +00:00
|
|
|
if icon.endswith('.jpg'):
|
|
|
|
icon_image = icon_image.convert('RGB')
|
2010-10-16 11:49:45 +00:00
|
|
|
icon_image.save(icon)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)')
|
|
|
|
parser.add_option('-l', '--timeline', dest='timeline', help='Timeline (image file to be read)')
|
|
|
|
parser.add_option('-i', '--icon', dest='icon', help='Icon (image file to be written)')
|
|
|
|
(options, args) = parser.parse_args()
|
2017-11-02 21:11:09 +00:00
|
|
|
if options.icon is None:
|
2010-10-16 11:49:45 +00:00
|
|
|
parser.print_help()
|
|
|
|
sys.exit()
|
2011-01-04 07:32:32 +00:00
|
|
|
render_icon(options.frame, options.timeline, options.icon)
|
2010-10-16 11:49:45 +00:00
|
|
|
|
2017-11-02 21:11:09 +00:00
|
|
|
|
2010-10-16 11:49:45 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|