From c385ef7ae073451e0c69c854d0c00c9aaa41baf8 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Sun, 17 May 2026 09:12:44 -0700 Subject: [PATCH] epub input: extract biggest image per page (#1342) * extract biggest image on page * fix largest_size location --- kindlecomicconverter/comic2ebook.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index 3b084d5..64667fc 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -980,17 +980,24 @@ def getWorkFolder(afile, workdir=None): page_path = os.path.join(os.path.dirname(opf_path), manifest_dict[spine_item]) page = ET.parse(page_path) imgs = page.findall(r'.//{*}img') + page.findall(r'.//{*}image') + + largest_size = 0 img_path = None - # TODO handle more than first image for img in imgs: for key in img.attrib: if 'src' in key or 'href' in key: - img_path = img.attrib[key] - if img_path.startswith('..'): - img_path = os.path.join(os.path.dirname(opf_path), os.path.dirname(manifest_dict[spine_item]), img_path) + temp_img_path = img.attrib[key] + if temp_img_path.startswith('..'): + temp_img_path = os.path.join(os.path.dirname(opf_path), os.path.dirname(manifest_dict[spine_item]), temp_img_path) else: - img_path = os.path.join(os.path.dirname(opf_path), os.path.dirname(manifest_dict[spine_item]), img_path) - break + temp_img_path = os.path.join(os.path.dirname(opf_path), os.path.dirname(manifest_dict[spine_item]), temp_img_path) + try: + temp_size = os.path.getsize(temp_img_path) + if temp_size > largest_size: + largest_size = temp_size + img_path = temp_img_path + except OSError: + pass # TODO empty image if img_path: ordered_image_paths.append(img_path)