2010-10-16 11:49:45 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2010-11-30 17:23:49 +00:00
|
|
|
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
|
|
|
|
|
|
|
|
#using virtualenv's activate_this.py to reorder sys.path
|
|
|
|
activate_this = os.path.join(root_dir, 'bin', 'activate_this.py')
|
|
|
|
execfile(activate_this, dict(__file__=activate_this))
|
|
|
|
|
2010-10-16 11:49:45 +00:00
|
|
|
from __future__ import division
|
|
|
|
import Image
|
|
|
|
import ImageDraw
|
|
|
|
from optparse import OptionParser
|
|
|
|
import os
|
|
|
|
from ox.image import drawText, wrapText
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
2010-11-18 17:33:46 +00:00
|
|
|
static_root = os.path.join(os.path.dirname(__file__), '..', '..', 'static')
|
2010-10-16 11:49:45 +00:00
|
|
|
|
|
|
|
def render_icon(frame, timeline, icon):
|
|
|
|
icon_width = 256
|
|
|
|
icon_height = 256
|
|
|
|
icon_image = Image.new('RGBA', (icon_width, icon_height))
|
|
|
|
frame_width = icon_width
|
|
|
|
frame_ratio = 4 / 3
|
|
|
|
frame_height = int(round(frame_width / frame_ratio))
|
|
|
|
frame_image = Image.open(frame)
|
|
|
|
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))
|
|
|
|
icon_image.paste(frame_image, (0, 0))
|
|
|
|
timeline_image = Image.open(timeline)
|
|
|
|
timeline_image = timeline_image.resize((icon_width, 64), Image.ANTIALIAS)
|
|
|
|
icon_image.paste(timeline_image, (0, icon_height - 64))
|
|
|
|
mask_image = Image.open(ox.path.join(static_root, 'png', 'icon.mask.png'))
|
|
|
|
mask_image = mask_image.resize((icon_width, icon_height))
|
|
|
|
icon_image.putalpha(mask_image)
|
|
|
|
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()
|
|
|
|
if options.icon == None:
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit()
|
|
|
|
render_icon(opt.frame, opt.timeline, opt.icon)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|