From 9343cdbdaca63ded9653d1c1552a1a540668b998 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 2 Jan 2014 12:02:38 +0100 Subject: [PATCH] Annotate pictures with source name. --- apps/picture/models.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/apps/picture/models.py b/apps/picture/models.py index 705025a7f..d8783cb62 100644 --- a/apps/picture/models.py +++ b/apps/picture/models.py @@ -233,6 +233,8 @@ class Picture(models.Model): img = picture_xml.image_file() modified = cls.crop_to_frame(picture_xml, img) + modified = cls.add_source_note(picture_xml, modified) + picture.width, picture.height = modified.size modified_file = StringIO() @@ -267,6 +269,26 @@ class Picture(models.Model): img = img.crop(itertools.chain(*wlpic.frame)) return img + @staticmethod + def add_source_note(wlpic, img): + from PIL import ImageDraw, ImageFont + from librarian import get_resource + + annotated = Image.new(img.mode, + (img.size[0], img.size[1] + 40), + (255, 255, 255) + ) + annotated.paste(img, (0, 0)) + annotation = Image.new(img.mode, (3000, 120), (255, 255, 255)) + ImageDraw.Draw(annotation).text( + (30, 15), + wlpic.picture_info.source_name, + (0, 0, 0), + font=ImageFont.truetype(get_resource("fonts/DejaVuSerif.ttf"), 75) + ) + annotated.paste(annotation.resize((1000, 40), Image.ANTIALIAS), (0, img.size[1])) + return annotated + @classmethod def picture_list(cls, filter=None): """Generates a hierarchical listing of all pictures -- 2.20.1