55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
|
#!/usr/bin/python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||
|
|
||
|
from __future__ import division
|
||
|
from optparse import OptionParser
|
||
|
import os
|
||
|
import sys
|
||
|
|
||
|
import Image
|
||
|
import ImageDraw
|
||
|
|
||
|
data_root = os.path.join(os.path.dirname(__file__), 'data')
|
||
|
|
||
|
def main():
|
||
|
|
||
|
parser = OptionParser()
|
||
|
parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)')
|
||
|
parser.add_option('-i', '--icon', dest='icon', help='Icon (image file to be written)')
|
||
|
(opts, args) = parser.parse_args()
|
||
|
if not opts.icon:
|
||
|
parser.print_help()
|
||
|
sys.exit()
|
||
|
|
||
|
iconSize = 1024
|
||
|
iconImage = Image.new('RGBA', (iconSize, iconSize))
|
||
|
|
||
|
if opts.frame:
|
||
|
frameImage = Image.open(opts.frame)
|
||
|
if frameImage.size[0] >= frameImage.size[1]:
|
||
|
frameWidth = int(frameImage.size[0] * iconSize / frameImage.size[1])
|
||
|
frameImage = frameImage.resize((frameWidth, iconSize), Image.ANTIALIAS)
|
||
|
crop = int((frameWidth - iconSize) / 2)
|
||
|
frameImage = frameImage.crop((crop, 0, crop + iconSize, iconSize))
|
||
|
else:
|
||
|
frameHeight = int(frameImage.size[1] * iconSize / frameImage.size[0])
|
||
|
frameImage = frameImage.resize((iconSize, frameHeight), Image.ANTIALIAS)
|
||
|
crop = int((frameHeight - iconSize) / 2)
|
||
|
frameImage = frameImage.crop((0, crop, iconSize, crop + iconSize))
|
||
|
iconImage.paste(frameImage, (0, 0, iconSize, iconSize))
|
||
|
else:
|
||
|
draw = ImageDraw.Draw(iconImage)
|
||
|
draw.polygon([(0, 0), (iconSize, 0), (iconSize, iconSize), (0, iconSize)], fill=(0, 0, 0))
|
||
|
for y in range(iconSize):
|
||
|
for x in range(iconSize):
|
||
|
if int((x + y + 192) / 128) % 2:
|
||
|
iconImage.putpixel((x, y), (32, 32, 32))
|
||
|
|
||
|
maskImage = Image.open(os.path.join(data_root, 'icon.mask.png'))
|
||
|
iconImage.putalpha(maskImage)
|
||
|
|
||
|
iconImage.save(opts.icon)
|
||
|
|
||
|
|