X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ab8ffbde2df33d9c699e029ba613d2b014ba44b8..6b07ba8b91eac4b6e4853fd3a01923c3f04f6016:/apps/picture/models.py?ds=sidebyside 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