Skip to content

Commit

Permalink
tests/test_extractimage.py: added test for pymupdf#2348.
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-smith-artifex-com committed Apr 18, 2023
1 parent c2f69e6 commit 050c87c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_extractimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,30 @@ def test_extract_image():
image_count += 1

assert image_count == known_image_count # this number is know about the file

def test_2348():

pdf_path = f'{scriptdir}/test_2348.pdf'
document = fitz.open()
page = document.new_page(width=500, height=842)
rect = fitz.Rect(20, 20, 480, 820)
page.insert_image(rect, filename=f'{scriptdir}/resources/nur-ruhig.jpg')
page = document.new_page(width=500, height=842)
page.insert_image(rect, filename=f'{scriptdir}/resources/img-transparent.png')
document.ez_save(pdf_path)
document.close()

document = fitz.open(pdf_path)
page = document[0]
imlist = page.get_images()
image = document.extract_image(imlist[0][0])
jpeg_extension = image['ext']

page = document[1]
imlist = page.get_images()
image = document.extract_image(imlist[0][0])
png_extension = image['ext']

print(f'jpeg_extension={jpeg_extension!r} png_extension={png_extension!r}')
assert jpeg_extension == 'jpeg'
assert png_extension == 'png'

0 comments on commit 050c87c

Please sign in to comment.