diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2014-02-28 00:37:05 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2014-02-28 00:37:05 -0500 |
| commit | ebd5024ec7e47ac85a41bf4d1ff98df15eb8cac3 (patch) | |
| tree | e535577f95da9c174f3c09f7363a8be5ad12c32c | |
| parent | 46ad59afebba9d43dd8b736b2e6844c2a77c9249 (diff) | |
| download | ocr-layer-curation-ebd5024ec7e47ac85a41bf4d1ff98df15eb8cac3.tar.gz | |
add a handler for images, everything is dynamic!
| -rw-r--r-- | web/main.py | 18 | ||||
| -rw-r--r-- | web/static/89.png | bin | 468695 -> 0 bytes | |||
| -rw-r--r-- | web/templates/index.html | 2 | ||||
| -rw-r--r-- | web/utils.py | 3 |
4 files changed, 17 insertions, 6 deletions
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 Binary files differdeleted file mode 100644 index 7497226..0000000 --- a/web/static/89.png +++ /dev/null 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 %} <div id="image_container"> - <img id="page" src="static/{{page_number}}.png" usemap="#wordmap" /> + <img id="page" src="{{page_number}}.png" usemap="#wordmap" /> </div> <map name="wordmap">{% for id, coords in areas %} <area href="#" shape="rect" coords="{{coords}}" data-id="{{id}}" />{% 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]) |
