when displaying a pdf page with a single image, also show the extracted image on its own for comparison

This commit is contained in:
xenofem 2024-04-04 08:15:18 -04:00
parent c4f5c776e2
commit a822a504e8

View file

@ -678,9 +678,9 @@ def get_displayed_image_xref(page):
debug(f"Multiple images found matching ref name {ref_names[0]}, that probably shouldn't happen")
return None
def display_sixel_page(page):
def display_sixel_pixmap(pixmap_bytes):
s = BytesIO()
image = Image.open(BytesIO(page.get_pixmap(dpi=PDF_PREVIEW_DPI).tobytes('png')))
image = Image.open(BytesIO(pixmap_bytes))
width, height = image.size
try:
@ -747,7 +747,11 @@ def pdf_images(pdf, strategy):
break
if choice.lower().startswith('s'):
display_sixel_page(page)
display_sixel_pixmap(page.get_pixmap(dpi=PDF_PREVIEW_DPI).tobytes('png'))
if xref is not None:
pixmap = fitz.Pixmap(pdf, xref)
pixmap.shrink(2)
display_sixel_pixmap(pixmap.tobytes('png'))
choice = input(f'[N]ope out / [c]onvert page{"" if xref is None else " / e[x]tract image"} / [d]rop page / [s]how page? [n/c{"" if xref is None else "/x"}/d/s] ')
print(f'\x1b[2K\r{idx+1}/{pdf.page_count} pages analyzed...', end=('' if idx+1 < pdf.page_count else '\n'))