From: Radek Czajka Date: Thu, 2 Jan 2014 11:02:38 +0000 (+0100) Subject: Annotate pictures with source name. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/9343cdbdaca63ded9653d1c1552a1a540668b998?ds=sidebyside Annotate pictures with source name. --- 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