This commit is contained in:
j 2010-09-17 17:43:01 +02:00
parent 1627b635ad
commit f441d624fb
7 changed files with 59 additions and 46 deletions

View File

@ -8,8 +8,8 @@ root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
if os.path.exists(os.path.join(root, 'oxgst')):
sys.path.insert(0, root)
from oxposter import poster
from oximage import oxdb_poster
if __name__ == "__main__":
poster.main()
oxdb_poster.main()

View File

@ -10,14 +10,14 @@ from ox.image import drawText, wrapText
data_root = os.path.join(os.path.dirname(__file__), 'data')
def render_list_icon(options):
def render_list_icon(frames, icon):
icon_width = 256
icon_height = 256
icon_image = Image.new('RGBA', (icon_width, icon_height))
frame_height = icon_height / 4
frame_ratio = 4 / 3
frame_width = int(round(frame_height * frame_ratio))
for i, frame in enumerate(options['frames']):
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)
@ -33,18 +33,17 @@ def render_list_icon(options):
mask_image = Image.open(ox.path.join(data_root, 'icon.mask.png'))
mask_image = mask_image.resize((icon_width, icon_height))
icon_image.putalpha(mask_image)
icon_image.save(options['icon'])
icon_image.save(icon)
def render_movie_icon(options):
def render_movie_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(options['frame'])
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)
@ -55,16 +54,15 @@ def render_movie_icon(options):
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(options['timeline'])
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(data_root, 'icon.mask.png'))
mask_image = mask_image.resize((icon_width, icon_height))
icon_image.putalpha(mask_image)
icon_image.save(options['icon'])
def render_oxdb_poster(options):
icon_image.save(icon)
def render_oxdb_poster(title, director, year, series, oxdb_id, imdb_id, frame, timeline, poster):
def get_oxdb_color(oxdb_id, series=False):
i = int(round((int(oxdb_id[2:10], 16) * 762 / pow(2, 32))))
if i < 127:
@ -83,8 +81,6 @@ def render_oxdb_poster(options):
color = tuple(map(lambda x: x + 128, color))
return color
options['title'] = options['title'].decode('utf-8')
options['director'] = options['director'].decode('utf-8')
poster_width = 640
poster_height = 1024
poster_ratio = poster_width / poster_height
@ -97,11 +93,11 @@ def render_oxdb_poster(options):
}
# frame
if options['frame']:
if frame:
frame_width = poster_width
frame_ratio = 4 / 3
frame_height = int(round(frame_width / frame_ratio))
frame_image = Image.open(options['frame'])
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)
@ -116,7 +112,7 @@ def render_oxdb_poster(options):
# timeline
timeline_width = poster_width
timeline_height = 64
timeline_image = Image.open(options['timeline'])
timeline_image = Image.open(timeline)
timeline_image = timeline_image.resize((timeline_width, timeline_height), Image.ANTIALIAS)
poster_image.paste(timeline_image, (0, frame_height))
@ -126,29 +122,29 @@ def render_oxdb_poster(options):
text_top = frame_height + timeline_height
text_bottom = text_top + text_height
text_margin = 16
text_color = get_oxdb_color(options['oxdb_id'], options['series'])
font_color = tuple(map(lambda x: x - 128 if options['series'] else x + 128, text_color))
text_color = get_oxdb_color(oxdb_id, series)
font_color = tuple(map(lambda x: x - 128 if series else x + 128, text_color))
draw.rectangle([(0, text_top), (text_width, text_bottom)], fill=text_color)
offset_top = text_top + text_margin
if not options['director']:
if not director:
title_max_lines = 7
else:
title_max_lines = min(len(wrapText(options['title'], text_width - 2 * text_margin, 0, font_file, font_size['large'])), 6)
title_max_lines = min(len(wrapText(title, text_width - 2 * text_margin, 0, font_file, font_size['large'])), 6)
director_max_lines = 9 - int((title_max_lines * 3 - 1) / 2)
if options['director']:
lines = wrapText(options['director'], text_width - 2 * text_margin, director_max_lines, font_file, font_size['small'])
if director:
lines = wrapText(director, text_width - 2 * text_margin, director_max_lines, font_file, font_size['small'])
for i, line in enumerate(lines):
size = drawText(poster_image, (text_margin, offset_top), line, font_file, font_size['small'], font_color)
offset_top += font_size['small'] + 2
offset_top += size[1] - font_size['small'] + text_margin / 2
lines = wrapText(options['title'], text_width - 2 * text_margin, title_max_lines, font_file, font_size['large'])
lines = wrapText(title, text_width - 2 * text_margin, title_max_lines, font_file, font_size['large'])
for i, line in enumerate(lines):
size = drawText(poster_image, (text_margin, offset_top + 5), line, font_file, font_size['large'], font_color)
offset_top += font_size['large'] + 3
offset_top += size[1] - font_size['small'] + text_margin / 2
if options['year']:
drawText(poster_image, (text_margin, offset_top), options['year'], font_file, font_size['small'], font_color)
drawText(poster_image, (text_margin, text_bottom - text_margin - font_size['large'] + 2), options['oxdb_id'], font_file, font_size['large'], font_color)
if year:
drawText(poster_image, (text_margin, offset_top), year, font_file, font_size['small'], font_color)
drawText(poster_image, (text_margin, text_bottom - text_margin - font_size['large'] + 2), oxdb_id, font_file, font_size['large'], font_color)
# logo
logo_height = 32
@ -162,15 +158,15 @@ def render_oxdb_poster(options):
poster_color = poster_image.getpixel((logo_left + x, logo_top + y))
logo_color = logo_image.getpixel((x, y))[0]
alpha = logo_image.getpixel((x, y))[3]
if options['series']:
if series:
poster_color = tuple(map(lambda x: x - (logo_color - 16) * alpha / 255, poster_color))
else:
poster_color = tuple(map(lambda x: x + (logo_color - 16) * alpha / 255, poster_color))
poster_image.putpixel((logo_left + x, logo_top + y), poster_color)
poster_image.save(options['poster'])
poster_image.save(poster)
def render_padma_poster(options):
def render_padma_poster(id, title, frame, timeline, poster):
poster_width = 640
poster_height = 1024
poster_ratio = poster_width / poster_height
@ -182,14 +178,14 @@ def render_padma_poster(options):
# timeline
timeline_height = 64
timeline_lines = 16
timeline_image = Image.open(options['timeline'])
timeline_image = Image.open(timeline)
timeline_image = timeline_image.resize((10240, timeline_height), Image.ANTIALIAS)
for i in range(timeline_lines):
line_image = timeline_image.crop((i * poster_width, 0, (i + 1) * poster_width, 64))
poster_image.paste(line_image, (0, i * timeline_height))
# id
text = 'Pad.ma/' + options['id']
text = 'Pad.ma/' + id
text_image = Image.new('RGB', (1, 1))
text_size = drawText(text_image, (0, 0), text, font_file, font_size, poster_color)
text_width = poster_width
@ -206,4 +202,4 @@ def render_padma_poster(options):
pixel[c] = (pixel[c] + poster_color[c]) / 4
poster_image.putpixel((x, y), tuple(pixel))
drawText(poster_image, ((poster_width - text_size[0]) / 2, text_top + (text_height - text_size[1]) / 2), text, font_file, font_size, poster_color)
poster_image.save(options['poster'])
poster_image.save(poster)

View File

@ -8,11 +8,13 @@ from imagetools import render_list_icon
def main():
parser = OptionParser()
parser.add_option('-f', '--frames', dest='frames', help='Poster frames (image files to be read)')
parser.add_option('-f', '--frames', dest='frames', help='Poster frames (image files to be read)', default='')
parser.add_option('-i', '--icon', dest='icon', help='Icon (image file to be written)')
(options, args) = parser.parse_args()
if options['icon'] == None:
if options.icon == None:
parser.print_help()
sys.exit()
options['frames'].replace(', ', ',').split(',')
render_list_icon(options)
frames = options.frames.replace(', ', ',').split(',')
render_list_icon(frames, opt.icon)

View File

@ -12,7 +12,7 @@ def main():
parser.add_option('-l', '--timeline', dest='frame', 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:
if options.icon == None:
parser.print_help()
sys.exit()
render_movie_icon(options)
render_movie_icon(opt.frame, opt.timeline, opt.icon)

View File

@ -11,14 +11,23 @@ def main():
parser.add_option('-o', '--oxdbid', dest='oxdb_id', help='0xDB Id')
parser.add_option('-i', '--imdbid', dest='imdb_id', help='IMDb Id')
parser.add_option('-t', '--title', dest='title', help='Title')
parser.add_option('-d', '--director', dest='director', help='Director(s)')
parser.add_option('-d', '--director', dest='director', help='Director(s)', default='')
parser.add_option('-y', '--year', dest='year', help='Year')
parser.add_option('-s', '--series', dest='series', help='Movie is an episode of a series', action='store_true')
parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)')
parser.add_option('-l', '--timeline', dest='frame', help='Timeline (image file to be read)')
parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)')
(options, args) = parser.parse_args()
if None in (options['oxdb_id'], options['title'], options['poster']):
if None in (options.oxdb_id, options.title, options.poster):
parser.print_help()
sys.exit()
render_oxdb_poster(options)
opt = {}
for key in ('oxdb_id', 'imdb_id', 'title', 'director', 'year', 'series', 'frame', 'poster'):
opt[key] = getattr(options, key)
opt['title'] = opt['title'].decode('utf-8')
opt['director'] = opt['director'].decode('utf-8')
render_oxdb_poster(**opt)

View File

@ -9,12 +9,18 @@ from imagetools import render_padma_poster
def main():
parser = OptionParser()
parser.add_option('-i', '--id', dest='id', help='Pad.ma Id')
parser.add_option('-t', '--title', dest='title', help='Title')
parser.add_option('-t', '--title', dest='title', help='Title', default='')
parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)')
parser.add_option('-l', '--timeline', dest='frame', help='Timeline (image file to be read)')
parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)')
(options, args) = parser.parse_args()
if None in (options['id'], options['poster']):
if None in (options.id, options.poster):
parser.print_help()
sys.exit()
render_padma_poster(options)
opt = {}
for key in ('id', 'title', 'frame', 'timeline', 'poster'):
opt[key] = getattr(options, key)
opt['title'] = opt['title'].decode('utf-8')
render_padma_poster(**opt)

View File

@ -7,7 +7,7 @@ from distutils.core import setup
setup(name="oxtools",
scripts = [
'bin/oximage',
'bin/oxposter',
],
packages = [
'oxgst',