new posters and icons

This commit is contained in:
Rolux 2010-09-17 16:40:10 +02:00
parent ab07ccc8ba
commit 3984264bc4
18 changed files with 290 additions and 214 deletions

BIN
oximage/data/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
oximage/data/icon.mask.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

207
oximage/imagetools.py Normal file
View File

@ -0,0 +1,207 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division
import Image
import ImageDraw
from ox.image import drawText, wrapText
def render_list_icon(options):
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']):
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))
icon_image.paste(frame_image, (i % 3 * frame_width + (1 if i % 2 == 2 else 0), int(i / 3) * frame_height))
mask_image = Image.open('icon.mask.png')
mask_image = mask_image.resize((icon_width, icon_height))
icon_image.putalpha(mask_image)
icon_image.save(options['icon'])
def render_movie_icon(options):
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_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(options['timeline'])
timeline_image = timeline_image.resize((icon_width, 64), Image.ANTIALIAS)
icon_image.paste(timeline_image, (0, icon_height - 64))
mask_image = Image.open('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):
def get_oxdb_color(oxdb_id, series=False):
i = int(round((int(oxdb_id[2:10], 16) * 762 / pow(2, 32))))
if i < 127:
color = (127, i, 0)
elif i < 254:
color = (254 - i, 127, 0)
elif i < 381:
color = (0, 127, i - 254)
elif i < 508:
color = (0, 508 - i, 127)
elif i < 635:
color = (i - 508, 0, 127)
else:
color = (127, 0, 762 - i)
if series:
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
poster_image = Image.new('RGB', (poster_width, poster_height))
draw = ImageDraw.Draw(poster_image)
font_file = 'data/DejaVuSansCondensedBold.ttf'
font_size = {
'small': 28,
'large': 42,
}
# frame
if options['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_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))
poster_image.paste(frame_image, (0, 0))
# timeline
timeline_width = poster_width
timeline_height = 64
timeline_image = Image.open(options['timeline'])
timeline_image = timeline_image.resize((timeline_width, timeline_height), Image.ANTIALIAS)
poster_image.paste(timeline_image, (0, frame_height))
# text
text_width = poster_width
text_height = poster_height - frame_height - timeline_height
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))
draw.rectangle([(0, text_top), (text_width, text_bottom)], fill=text_color)
offset_top = text_top + text_margin
if not options['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)
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'])
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'])
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), 'France/West Germany, ' + options['year'] + ', 120 min', 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)
# logo
logo_height = 32
logo_image = Image.open('data/logo.poster.png')
logo_width = int(round(logo_height * logo_image.size[0] / logo_image.size[1]))
logo_image = logo_image.resize((logo_width, logo_height), Image.ANTIALIAS)
logo_left = text_width - text_margin - logo_width
logo_top = text_bottom - text_margin - logo_height
for y in range(logo_height):
for x in range(logo_width):
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']:
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'])
def render_padma_poster(options):
poster_width = 640
poster_height = 1024
poster_ratio = poster_width / poster_height
poster_color = (255, 255, 0)
poster_image = Image.new('RGB', (poster_width, poster_height))
font_file = 'data/DejaVuSansCondensedBold.ttf'
font_size = 48
# timeline
timeline_height = 64
timeline_lines = 16
timeline_image = Image.open(options['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_image = Image.new('RGB', (1, 1))
text_size = drawText(text_image, (0, 0), text, font_file, font_size, poster_color)
text_width = poster_width
text_height = timeline_height
text_left = int((poster_width - text_width) / 2)
text_top = 14 * timeline_height
for y in range(text_top, text_top + text_height):
for x in range(text_left, text_left + text_width):
if y < text_top + 4 or y >= text_top + text_height - 4:
poster_image.putpixel((x, y), poster_color)
else:
pixel = list(poster_image.getpixel((x, y)))
for c in range(3):
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'])

18
oximage/list_icon.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import sys
from optparse import OptionParser
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('-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()
options['frames'].replace(', ', ',').split(',')
render_list_icon(options)

18
oximage/movie_icon.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import sys
from optparse import OptionParser
from imagetools import render_movie_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='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:
parser.print_help()
sys.exit()
render_movie_icon(options)

24
oximage/oxdb_poster.py Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import sys
from optparse import OptionParser
from imagetools import render_oxdb_poster
def main():
parser = OptionParser()
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('-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']):
parser.print_help()
sys.exit()
render_oxdb_poster(options)

20
oximage/padma_poster.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import sys
from optparse import OptionParser
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('-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']):
parser.print_help()
sys.exit()
render_padma_poster(options)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -1,54 +0,0 @@
#!/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)

View File

@ -1,155 +0,0 @@
# -*- 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
from ox import truncateString, wrapString
data_root = os.path.join(os.path.dirname(__file__), 'data')
def main():
parser = OptionParser()
parser.add_option('-o', '--oxdb', dest='oxdb', help='0xdb Id')
parser.add_option('-i', '--imdb', dest='imdb', help='IMDb Id')
parser.add_option('-t', '--title', dest='title', help='Movie title')
parser.add_option('-d', '--director', dest='director', help='Director(s)')
parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)')
parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)')
parser.add_option('-r', '--restricted', action='store_true', dest='restricted', help='If set, poster frame will have overlay')
(opts, args) = parser.parse_args()
if None in (opts.oxdb, opts.title, opts.director, opts.poster):
parser.print_help()
sys.exit()
opts.oxdb = '%s%s' % (opts.oxdb[:2], opts.oxdb[2:8].upper())
opts.title = opts.title.decode('utf-8')
opts.director = opts.director.decode('utf-8')
if opts.imdb == None:
id = opts.oxdb
else:
id = opts.imdb
posterWidth = 640
posterHeight = 1024
posterImage = Image.new('RGB', (posterWidth, posterHeight))
fontImage = Image.open(os.path.join(data_root, 'font.monaco.bold.png'))
oxdbImage = Image.open(os.path.join(data_root, 'logo.0xdb.large.png'))
# frame section
frameHeight = int(posterWidth * 10 / 16)
if opts.frame:
frameImage = Image.open(opts.frame)
if frameImage.size[0] / frameImage.size[1] > posterWidth / frameHeight:
# poster frame is too wide
frameImage = frameImage.resize((int(frameImage.size[0] * frameHeight / frameImage.size[1]), frameHeight), Image.ANTIALIAS)
crop = int((frameImage.size[0] - posterWidth) / 2)
frameImage = frameImage.crop((crop, 0, crop + posterWidth, frameHeight))
else:
# poster frame is not wide enough
frameImage = frameImage.resize((posterWidth, int(frameImage.size[1] * posterWidth / frameImage.size[0])), Image.ANTIALIAS)
crop = int((frameImage.size[1] - frameHeight) / 2)
frameImage = frameImage.crop((0, crop, posterWidth, crop + frameHeight))
posterImage.paste(frameImage, (0, 0, posterWidth, frameHeight))
else:
draw = ImageDraw.Draw(posterImage)
draw.polygon([(0, 0), (posterWidth, 0), (posterWidth, frameHeight), (0, frameHeight)], fill=(0, 0, 0))
for y in range(frameHeight):
for x in range(posterWidth):
if int((x + y + 54) / 128) % 2:
posterImage.putpixel((x, y), (32, 32, 32))
# restricted
if opts.restricted:
for y in range(frameHeight):
for x in range(posterWidth):
if int((x + y + 54) / 128) % 2:
rgb = posterImage.getpixel((x, y))
rgb = (int(rgb[0] / 2) + 128, int(rgb[1] / 2), int(rgb[2] / 2))
posterImage.putpixel((x, y), rgb)
# director section
colorHeight = int(posterHeight / 2);
draw = ImageDraw.Draw(posterImage)
draw.polygon([(0, frameHeight), (posterWidth, frameHeight), (posterWidth, colorHeight), (0, colorHeight)], fill=(0, 0, 0))
director = wrapString(opts.director, 36, '\n', True)
while len(director.split('\n')) > 3:
director = opts.director.split(', ')
director.pop()
opts.director = ', '.join(director)
director = wrapString(opts.director, 36, '\n', True)
posterMargin = 16
imagewrite(posterImage, director, posterMargin, colorHeight - 8 - len(director.split('\n')) * 32, fontImage, 32)
# title section
backgroundColor = getRGB(opts.oxdb)
draw.polygon([(0, colorHeight), (posterWidth, colorHeight), (posterWidth, posterHeight), (0, posterHeight)], fill=backgroundColor)
title = wrapString(opts.title, 24, '\n', True)
lines = title.split('\n')
if lines > 8:
# following line commented out since the only known case
# (http://0xdb.org/0071458) looks better without '...'
# lines[7] = truncateString(lines[7] + '...', 24)
title = '\n'.join(lines[:8])
offset = -6
posterimage = imagewrite(posterImage, title, posterMargin, colorHeight + posterMargin + offset, fontImage, 48)
offset = 12
posterimage = imagewrite(posterImage, id, posterMargin, posterHeight - posterMargin - 96 + offset, fontImage, 96)
# 0xdb logo
x = posterWidth - oxdbImage.size[0] - posterMargin
y = posterHeight - oxdbImage.size[1] - posterMargin
for dy in range(oxdbImage.size[1]):
for dx in range(oxdbImage.size[0]):
rgb = posterImage.getpixel((x + dx, y + dy))
bw = oxdbImage.getpixel((dx, dy))[0]
rgb = tuple(map(lambda x : x + bw, rgb))
posterImage.putpixel((x + dx, y + dy), rgb)
posterImage.save(opts.poster)
def getRGB(oxid):
i = int(int(oxid[2:8], 16) * 762 / 16777216)
if i < 127:
return (127, i, 0)
elif i < 254:
return (254 - i, 127, 0)
elif i < 381:
return (0, 127, i - 254)
elif i < 508:
return (0, 508 - i, 127)
elif i < 635:
return (i - 508, 0, 127)
else:
return (127, 0, 762 - i)
def imagewrite(posterImage, string, left, top, fontImage, charHeight):
x = left
y = top
fontWidth = int(fontImage.size[0] / 16)
fontHeight = int(fontImage.size[1] / 16)
charWidth = int(fontWidth * charHeight / fontHeight)
for i in range(len(string)):
char = string[i:i+1]
if char == '\n':
x = left
y += charHeight
else:
ascii = ord(char)
fontLeft = (ascii % 16) * fontWidth
fontTop = int(ascii / 16) * fontHeight
letterImage = fontImage.crop((fontLeft, fontTop, fontLeft + fontWidth, fontTop + fontHeight))
letterImage = letterImage.resize((charWidth, charHeight), Image.ANTIALIAS)
for dy in range(charHeight):
for dx in range(charWidth):
rgb = posterImage.getpixel((x + dx, y + dy))
bw = int(letterImage.getpixel((dx, dy))[0] / 2)
rgb = tuple(map(lambda x : x + bw, rgb))
posterImage.putpixel((x + dx, y + dy), rgb)
x += charWidth
return posterImage

View File

@ -7,16 +7,14 @@ from distutils.core import setup
setup(name="oxtools",
scripts = [
'bin/oxicon',
'bin/oxposter',
'bin/oxtimeline',
'bin/oximage',
],
packages = [
'oxgst',
'oxposter',
'oximage',
],
package_data = {
'oxposter': ['data/*.png'],
'oximage': ['data/*.png', 'data/*.ttf'],
},
version="0.1",
author="j",