1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.core.management.base import BaseCommand
7 from catalogue.models import Book
8 from librarian.cover import make_cover
11 class Command(BaseCommand):
12 def add_arguments(self, parser):
13 parser.add_argument('slug')
14 parser.add_argument('--width', type=int)
15 parser.add_argument('--height', type=int)
16 parser.add_argument('--bleed', action='store_true')
17 parser.add_argument('--cover-class', type=str)
19 def handle(self, *args, **options):
20 slug = options['slug']
21 width = options['width']
22 height = options.get('height')
23 cover_class = options.get('cover_class')
24 bleed = 20 if options['bleed'] else 0
25 wldoc = Book.objects.get(slug=slug).wldocument()
28 kwargs['cover_class'] = cover_class
29 cover = make_cover(wldoc.book_info, width=width, height=height, bleed=bleed, **kwargs)
30 cover.save('%s.jpg' % slug)