#!/usr/bin/python
import os, glob
class Book:
def get_filename(self, i):
return "%s-%dx%d.html" % (self.image_file_list[i],
self.width, self.height)
def MainImage(self, i):
image_file = self.image_file_list[i]
n = i + 1;
if n >= len(self.image_file_list):
return """
The End
|
""" % (self.width, image_file,
self.width, self.height,
image_file, image_file)
else:
return """

%s -- Click on the image to turn the page.
|
""" % (self.width, self.get_filename(n),
image_file, self.width, self.height,
image_file, image_file, image_file)
def ImageTemplate(self, i, divisor):
width = self.width / divisor
height = self.height / divisor
empty = """ | """ % (width)
if i < 0 or i >= len(self.image_file_list):
return empty
image_file = self.image_file_list[i]
img_template = """

%s
|
""" % (width, self.get_filename(i),
image_file, width, height,
image_file, image_file, image_file)
return img_template
def __init__(self, title, author, width, height):
self.title = title
self.author = author
self.width = width
self.height = height
def WriteHTML(self):
# read all the jpegs in the current directory
self.image_file_list = glob.glob("*.jpg")
self.image_file_list.sort()
for i in range(len(self.image_file_list)):
image_file = self.image_file_list[i]
main_page = self.MainImage(i)
page = self.ImageTemplate(i-2, 6) + \
self.ImageTemplate(i-1, 6) + \
self.ImageTemplate(i+0, 6) + \
self.ImageTemplate(i+1, 5) + \
self.ImageTemplate(i+2, 6) + \
self.ImageTemplate(i+3, 6)
html = """
%s - %s
%s
""" % (self.title, image_file, self.author, main_page, page)
open(self.get_filename(i), "w").write(html)
if __name__ == "__main__":
b = Book(title = "The History of American Currency",
author = "William G. Sumner",
width = 2272, # native camera resolution
height = 1704)
b.WriteHTML()
b = Book(title = "The History of American Currency",
author = "William G. Sumner",
width = 1400, # native camera resolution
height = 1024)
b.WriteHTML()
b = Book(title = "The History of American Currency",
author = "William G. Sumner",
width = 1024, # native camera resolution
height = 768)
b.WriteHTML()