mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-23 13:36:22 +01:00
Use correct 3:4 aspect ratio for default cover image
This commit is contained in:
parent
8207ff2f61
commit
ae1446a91d
5 changed files with 3210 additions and 8 deletions
3191
resources/images/default_cover.svg
Normal file
3191
resources/images/default_cover.svg
Normal file
File diff suppressed because it is too large
Load diff
|
After Width: | Height: | Size: 105 KiB |
|
|
@ -248,7 +248,7 @@ def info_dialog(parent, title, msg, det_msg='', show=False):
|
|||
|
||||
class Dispatcher(QObject):
|
||||
'''Convenience class to ensure that a function call always happens in the
|
||||
thread the reciver was created in.'''
|
||||
thread the receiver was created in.'''
|
||||
dispatch_signal = pyqtSignal(object, object)
|
||||
|
||||
def __init__(self, func):
|
||||
|
|
@ -507,7 +507,7 @@ def pixmap_to_data(pixmap, format='JPEG'):
|
|||
buf = QBuffer(ba)
|
||||
buf.open(QBuffer.WriteOnly)
|
||||
pixmap.save(buf, format)
|
||||
return str(ba.data())
|
||||
return bytes(ba.data())
|
||||
|
||||
class ResizableDialog(QDialog):
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||
COVER_FETCH_TIMEOUT = 240 # seconds
|
||||
|
||||
def do_reset_cover(self, *args):
|
||||
pix = QPixmap(I('book.svg'))
|
||||
pix = QPixmap(I('default_cover.svg'))
|
||||
self.cover.setPixmap(pix)
|
||||
self.cover_changed = True
|
||||
self.cover_data = None
|
||||
|
|
@ -408,7 +408,7 @@ def __init__(self, window, row, db, accepted_callback=None, cancel_all=False):
|
|||
if cover:
|
||||
pm.loadFromData(cover)
|
||||
if pm.isNull():
|
||||
pm = QPixmap(I('book.svg'))
|
||||
pm = QPixmap(I('default_cover.svg'))
|
||||
else:
|
||||
self.cover_data = cover
|
||||
self.cover.setPixmap(pm)
|
||||
|
|
|
|||
|
|
@ -43,6 +43,14 @@ def __new__(cls, path, orig_file_path):
|
|||
ans.deleted_after_upload = False
|
||||
return ans
|
||||
|
||||
_default_image = None
|
||||
|
||||
def default_image():
|
||||
global _default_image
|
||||
if _default_image is None:
|
||||
_default_image = QImage(I('default_cover.svg'))
|
||||
return _default_image
|
||||
|
||||
class BooksModel(QAbstractTableModel): # {{{
|
||||
|
||||
about_to_be_sorted = pyqtSignal(object, name='aboutToBeSorted')
|
||||
|
|
@ -71,7 +79,7 @@ def __init__(self, parent=None, buffer=40):
|
|||
self.book_on_device = None
|
||||
self.editable_cols = ['title', 'authors', 'rating', 'publisher',
|
||||
'tags', 'series', 'timestamp', 'pubdate']
|
||||
self.default_image = QImage(I('book.svg'))
|
||||
self.default_image = default_image()
|
||||
self.sorted_on = DEFAULT_SORT
|
||||
self.sort_history = [self.sorted_on]
|
||||
self.last_search = '' # The last search performed on this model
|
||||
|
|
|
|||
|
|
@ -539,17 +539,20 @@ def opts_and_exts(name, op, exts):
|
|||
</mime-info>
|
||||
'''
|
||||
|
||||
def render_svg(image, dest):
|
||||
def render_svg(image, dest, width=128, height=128):
|
||||
from PyQt4.QtGui import QPainter, QImage
|
||||
from PyQt4.QtSvg import QSvgRenderer
|
||||
svg = QSvgRenderer(image.readAll())
|
||||
image = image.readAll() if hasattr(image, 'readAll') else image
|
||||
svg = QSvgRenderer(image)
|
||||
painter = QPainter()
|
||||
image = QImage(128,128,QImage.Format_ARGB32_Premultiplied)
|
||||
image = QImage(width, height, QImage.Format_ARGB32)
|
||||
painter.begin(image)
|
||||
painter.setRenderHints(QPainter.Antialiasing|QPainter.TextAntialiasing|QPainter.SmoothPixmapTransform|QPainter.HighQualityAntialiasing)
|
||||
painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
|
||||
svg.render(painter)
|
||||
painter.end()
|
||||
if dest is None:
|
||||
return image
|
||||
image.save(dest)
|
||||
|
||||
def main():
|
||||
|
|
|
|||
Loading…
Reference in a new issue