mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
This time, do json thumbnails right.
This commit is contained in:
parent
e73b688ca8
commit
e0261c2ba1
@ -12,7 +12,7 @@ from calibre.ebooks.metadata.book import SERIALIZABLE_FIELDS
|
|||||||
from calibre.constants import filesystem_encoding, preferred_encoding
|
from calibre.constants import filesystem_encoding, preferred_encoding
|
||||||
from calibre.library.field_metadata import FieldMetadata
|
from calibre.library.field_metadata import FieldMetadata
|
||||||
from calibre.utils.date import parse_date, isoformat, UNDEFINED_DATE
|
from calibre.utils.date import parse_date, isoformat, UNDEFINED_DATE
|
||||||
from calibre.utils.magick.draw import identify_data
|
from calibre.utils.magick import Image
|
||||||
from calibre import isbytestring
|
from calibre import isbytestring
|
||||||
|
|
||||||
# Translate datetimes to and from strings. The string form is the datetime in
|
# Translate datetimes to and from strings. The string form is the datetime in
|
||||||
@ -33,12 +33,15 @@ def encode_thumbnail(thumbnail):
|
|||||||
'''
|
'''
|
||||||
if thumbnail is None:
|
if thumbnail is None:
|
||||||
return None
|
return None
|
||||||
if isinstance(thumbnail, tuple):
|
if not isinstance(thumbnail, tuple):
|
||||||
try:
|
try:
|
||||||
thumbnail = identify_data(thumbnail)
|
img = Image()
|
||||||
|
img.load(thumbnail)
|
||||||
|
width, height = img.size
|
||||||
|
thumbnail = (width, height, thumbnail)
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
return (0, 0, b64encode(str(thumbnail)))
|
return (thumbnail[0], thumbnail[1], b64encode(str(thumbnail[2])))
|
||||||
|
|
||||||
def decode_thumbnail(tup):
|
def decode_thumbnail(tup):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user