From ebd5024ec7e47ac85a41bf4d1ff98df15eb8cac3 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Fri, 28 Feb 2014 00:37:05 -0500 Subject: add a handler for images, everything is dynamic! --- web/main.py | 18 +++++++++++++++--- web/static/89.png | Bin 468695 -> 0 bytes web/templates/index.html | 2 +- web/utils.py | 3 +-- 4 files changed, 17 insertions(+), 6 deletions(-) delete mode 100644 web/static/89.png diff --git a/web/main.py b/web/main.py index 09fbcbf..81e8252 100644 --- a/web/main.py +++ b/web/main.py @@ -3,7 +3,8 @@ from tornado.web import RequestHandler, Application import tornado.ioloop from settings import settings import utils - +from parsedjvutext import image_from_book +import io class MainHandler(RequestHandler): @@ -12,10 +13,21 @@ class MainHandler(RequestHandler): self.render("index.html", page_number=page_number, areas=areas, words=words) +class ImageHandler(RequestHandler): + + def get(self, page_number): + im = image_from_book("../Villiers_de_L'Isle-Adam_-_Tribulat_Bonhomet,_1908.djvu", int(page_number)) + self.set_header('Content-Type', 'image/png') + img_buff = io.BytesIO() + im.save(img_buff, format="PNG") + img_buff.seek(0) + self.write(img_buff.read()) + self.finish() application = Application([ - (r'/(\d+)/?', MainHandler) -], **settings) + (r'/(\d+)/?', MainHandler), + (r'/(\d+)\.png/?', ImageHandler)] + , **settings) if __name__ == '__main__': http_server = tornado.httpserver.HTTPServer(application) diff --git a/web/static/89.png b/web/static/89.png deleted file mode 100644 index 7497226..0000000 Binary files a/web/static/89.png and /dev/null differ diff --git a/web/templates/index.html b/web/templates/index.html index b39017e..a3dec33 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -2,7 +2,7 @@ {% block main %}
- +
{% for id, coords in areas %} {% end %} diff --git a/web/utils.py b/web/utils.py index 3db0296..8c7a33e 100644 --- a/web/utils.py +++ b/web/utils.py @@ -7,8 +7,7 @@ def gen_html(book, page_number): d = parse_book(book, page=int(page_number), html=True) if d[0]: words, coords = zip(*d[0]) - - return (list(enumerate(coords)), list(enumerate(words))) + return (list(enumerate(coords)), list(enumerate(words))) if __name__ == "__main__": gen_html(*sys.argv[1:3]) -- cgit v1.2.3-70-g09d2