mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ODT Input: Only use the first image as cover
ODT Input: Only treat the first image as a cover if it is of suitable size, instead of any image in the document. See #1224157 (ODT to MOBI - Images - Cover Image will not removed and other images are missed)
This commit is contained in:
parent
f1d49a1cb1
commit
187eb4e065
@ -224,26 +224,28 @@ def read_cover(stream, zin, mi, opfmeta, extract_cover):
|
||||
cover_href = None
|
||||
cover_data = None
|
||||
cover_frame = None
|
||||
imgnum = 0
|
||||
for frm in otext.topnode.getElementsByType(odFrame):
|
||||
img = frm.getElementsByType(odImage)
|
||||
if len(img) > 0: # there should be only one
|
||||
i_href = img[0].getAttribute('href')
|
||||
try:
|
||||
raw = zin.read(i_href)
|
||||
except KeyError:
|
||||
continue
|
||||
try:
|
||||
width, height, fmt = identify_data(raw)
|
||||
except:
|
||||
continue
|
||||
else:
|
||||
if len(img) == 0:
|
||||
continue
|
||||
i_href = img[0].getAttribute('href')
|
||||
try:
|
||||
raw = zin.read(i_href)
|
||||
except KeyError:
|
||||
continue
|
||||
try:
|
||||
width, height, fmt = identify_data(raw)
|
||||
except:
|
||||
continue
|
||||
imgnum += 1
|
||||
if opfmeta and frm.getAttribute('name').lower() == u'opf.cover':
|
||||
cover_href = i_href
|
||||
cover_data = (fmt, raw)
|
||||
cover_frame = frm.getAttribute('name') # could have upper case
|
||||
break
|
||||
if cover_href is None and 0.8 <= height/width <= 1.8 and height*width >= 12000:
|
||||
if cover_href is None and imgnum == 1 and 0.8 <= height/width <= 1.8 and height*width >= 12000:
|
||||
# Pick the first image as the cover if it is of a suitable size
|
||||
cover_href = i_href
|
||||
cover_data = (fmt, raw)
|
||||
if not opfmeta:
|
||||
|
Loading…
x
Reference in New Issue
Block a user