mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #6724 (Add series info to "Generate cover")
This commit is contained in:
parent
965413b392
commit
f8541561f7
@ -138,3 +138,11 @@ def check_ebook_format(stream, current_guess):
|
|||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def calibre_cover(title, author_string, series_string=None,
|
||||||
|
output_format='jpg', title_size=46, author_size=36):
|
||||||
|
from calibre.utils.magick.draw import create_cover_page, TextLine
|
||||||
|
lines = [TextLine(title, title_size), TextLine(author_string, author_size)]
|
||||||
|
if series_string:
|
||||||
|
lines.append(TextLine(series_string, author_size))
|
||||||
|
return create_cover_page(lines, I('library.png'), output_format='jpg')
|
||||||
|
|
||||||
|
@ -89,19 +89,22 @@ class CoverManager(object):
|
|||||||
'''
|
'''
|
||||||
Create a generic cover for books that dont have a cover
|
Create a generic cover for books that dont have a cover
|
||||||
'''
|
'''
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string, fmt_sidx
|
||||||
if self.no_default_cover:
|
if self.no_default_cover:
|
||||||
return None
|
return None
|
||||||
self.log('Generating default cover')
|
self.log('Generating default cover')
|
||||||
m = self.oeb.metadata
|
m = self.oeb.metadata
|
||||||
title = unicode(m.title[0])
|
title = unicode(m.title[0])
|
||||||
authors = [unicode(x) for x in m.creator if x.role == 'aut']
|
authors = [unicode(x) for x in m.creator if x.role == 'aut']
|
||||||
|
series_string = None
|
||||||
|
if m.series and m.series_index:
|
||||||
|
series_string = _('Book %s of %s')%(
|
||||||
|
fmt_sidx(m.series_index[0], use_roman=True), m.series[0])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from calibre.utils.magick.draw import create_cover_page, TextLine
|
from calibre.ebooks import calibre_cover
|
||||||
lines = [TextLine(title, 44), TextLine(authors_to_string(authors),
|
img_data = calibre_cover(title, authors_to_string(authors),
|
||||||
32)]
|
series_string=series_string)
|
||||||
img_data = create_cover_page(lines, I('library.png'))
|
|
||||||
id, href = self.oeb.manifest.generate('cover_image',
|
id, href = self.oeb.manifest.generate('cover_image',
|
||||||
'cover_image.jpg')
|
'cover_image.jpg')
|
||||||
item = self.oeb.manifest.add(id, href, guess_type('t.jpg')[0],
|
item = self.oeb.manifest.add(id, href, guess_type('t.jpg')[0],
|
||||||
|
@ -144,15 +144,23 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
self.cover_data = cover
|
self.cover_data = cover
|
||||||
|
|
||||||
def generate_cover(self, *args):
|
def generate_cover(self, *args):
|
||||||
from calibre.utils.magick.draw import create_cover_page, TextLine
|
from calibre.ebooks import calibre_cover
|
||||||
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
|
from calibre.gui2 import config
|
||||||
title = unicode(self.title.text()).strip()
|
title = unicode(self.title.text()).strip()
|
||||||
author = unicode(self.authors.text()).strip()
|
author = unicode(self.authors.text()).strip()
|
||||||
if not title or not author:
|
if not title or not author:
|
||||||
return error_dialog(self, _('Specify title and author'),
|
return error_dialog(self, _('Specify title and author'),
|
||||||
_('You must specify a title and author before generating '
|
_('You must specify a title and author before generating '
|
||||||
'a cover'), show=True)
|
'a cover'), show=True)
|
||||||
lines = [TextLine(title, 44), TextLine(author, 32)]
|
series = unicode(self.series.text()).strip()
|
||||||
self.cover_data = create_cover_page(lines, I('library.png'))
|
series_string = None
|
||||||
|
if series:
|
||||||
|
series_string = _('Book %s of %s')%(
|
||||||
|
fmt_sidx(self.series_index.value(),
|
||||||
|
use_roman=config['use_roman_numerals_for_series_number']), series)
|
||||||
|
self.cover_data = calibre_cover(title, author,
|
||||||
|
series_string=series_string)
|
||||||
pix = QPixmap()
|
pix = QPixmap()
|
||||||
pix.loadFromData(self.cover_data)
|
pix.loadFromData(self.cover_data)
|
||||||
self.cover.setPixmap(pix)
|
self.cover.setPixmap(pix)
|
||||||
|
@ -1018,12 +1018,11 @@ class BasicNewsRecipe(Recipe):
|
|||||||
Create a generic cover for recipes that dont have a cover
|
Create a generic cover for recipes that dont have a cover
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
from calibre.utils.magick.draw import create_cover_page, TextLine
|
from calibre.ebooks import calibre_cover
|
||||||
title = self.title if isinstance(self.title, unicode) else \
|
title = self.title if isinstance(self.title, unicode) else \
|
||||||
self.title.decode(preferred_encoding, 'replace')
|
self.title.decode(preferred_encoding, 'replace')
|
||||||
date = strftime(self.timefmt)
|
date = strftime(self.timefmt)
|
||||||
lines = [TextLine(title, 44), TextLine(date, 32)]
|
img_data = calibre_cover(title, date)
|
||||||
img_data = create_cover_page(lines, I('library.png'), output_format='jpg')
|
|
||||||
cover_file.write(img_data)
|
cover_file.write(img_data)
|
||||||
cover_file.flush()
|
cover_file.flush()
|
||||||
except:
|
except:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user