Skip to content

Commit

Permalink
use a context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
koaning committed Oct 5, 2023
1 parent 99f0206 commit 0bcad08
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions prodigy_pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

def page_to_image(page: pdfium.PdfPage) -> str:
pil_image = page.render().to_pil()
buffered = BytesIO()
pil_image.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue())
with BytesIO() as buffered:
pil_image.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue())
return f"data:image/png;base64,{img_str.decode('utf-8')}"


Expand Down

0 comments on commit 0bcad08

Please sign in to comment.