X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ab8ffbde2df33d9c699e029ba613d2b014ba44b8..0bd2c341a8b55f817c2e193a6c4658d52ef95961:/apps/picture/models.py?ds=inline diff --git a/apps/picture/models.py b/apps/picture/models.py index 705025a7f..a0179de53 100644 --- a/apps/picture/models.py +++ b/apps/picture/models.py @@ -1,3 +1,7 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# from django.db import models, transaction import catalogue.models from django.db.models import permalink @@ -233,6 +237,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 +273,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