2017-11-02 21:08:17 +00:00
|
|
|
#!/usr/bin/env python3
|
2010-10-16 11:49:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
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
|
|
|
|
from PIL import ImageDraw
|
2010-10-16 11:49:45 +00:00
|
|
|
from optparse import OptionParser
|
|
|
|
from ox.image import drawText, wrapText
|
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_list_icon(frames, icon):
|
|
|
|
icon_width = 256
|
|
|
|
icon_height = 256
|
|
|
|
icon_image = Image.new('RGBA', (icon_width, icon_height))
|
2011-09-29 13:05:34 +00:00
|
|
|
frame_height = int(icon_height / 2)
|
|
|
|
frame_ratio = 1
|
2010-10-16 11:49:45 +00:00
|
|
|
frame_width = int(round(frame_height * frame_ratio))
|
|
|
|
for i, frame in enumerate(frames):
|
|
|
|
frame_image = Image.open(frame)
|
|
|
|
frame_image_ratio = frame_image.size[0] / frame_image.size[1]
|
|
|
|
frame_width_ = frame_width + (1 if i % 2 == 1 else 0)
|
|
|
|
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-09-29 13:05:34 +00:00
|
|
|
icon_image.paste(frame_image, (i % 2 * frame_width + (1 if i % 2 == 2 else 0),
|
|
|
|
int(i / 2) * frame_height))
|
2011-10-27 23:16:43 +00:00
|
|
|
mask_image = Image.open(os.path.join(static_root, 'iconMask.png'))
|
2010-10-16 11:49:45 +00:00
|
|
|
mask_image = mask_image.resize((icon_width, icon_height))
|
|
|
|
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', '--frames', dest='frames', help='Poster frames (image files to be read)', default='')
|
2011-09-29 13:05:34 +00:00
|
|
|
parser.add_option('-o', '--icon', dest='icon', help='Icon (image file to be written)')
|
2010-10-16 11:49:45 +00:00
|
|
|
(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()
|
|
|
|
|
|
|
|
frames = options.frames.replace(', ', ',').split(',')
|
|
|
|
|
2011-09-29 13:05:34 +00:00
|
|
|
render_list_icon(frames, 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()
|