Imagegeneration for Kindle 4

Task: Generate images displayable on a Kindle 4.

Example code using Python and Pillow:

# -*- coding: utf-8 -*-
from PIL import Image, ImageDraw, ImageFont

image = Image.new("P", (600,800), 255)

# generate a 8 bit greyscale palette
def palette():
  for i in range(0,256):
    yield i;yield i; yield i

image.putpalette(
  list(palette())
)

draw = ImageDraw.Draw(image)

# needs a TrueType font
font_name = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf"
font = ImageFont.truetype(font_name, 100)
# set some text including some unicode
txt = u"TEXT \u2600 \u2602 \u2603"

draw.text((10, 0), txt, 0, font=font)
image.convert('L').save("kindle-image.png", "png")

Comments