diff --git a/CHANGELOG.md b/CHANGELOG.md index 49ee7bb4..57eeed7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Currently g The format is based on [Keep a Changelog](http://keepachangelog.com/). +## [0.5.20] — 2020-04-28 +### Fixed +- TKTK + ## [0.5.19] — 2020-04-16 ### Changed - Add `utils.decimalize` performance improvement (830d117) [h/t @ubmarco] diff --git a/pdfplumber/display.py b/pdfplumber/display.py index 87d21be7..909a73e1 100644 --- a/pdfplumber/display.py +++ b/pdfplumber/display.py @@ -21,9 +21,20 @@ def get_page_image(stream, page_no, resolution): """ For kwargs, see http://docs.wand-py.org/en/latest/wand/image.html#wand.image.Image """ - stream.seek(0) - with wand.image.Image(file=stream, resolution=resolution) as pages: - img = wand.image.Image(image=pages.sequence[page_no]) + + # If we are working with a file object saved to disk + if hasattr(stream, "name"): + spec = dict(filename = "{0}[{1}]".format(stream.name, page_no)) + postprocess = lambda img: img + + # If we instead are working with a BytesIO stream + else: + stream.seek(0) + spec = dict(file = stream) + postprocess = lambda img: wand.image.Image(image=img.sequence[page_no]) + + with wand.image.Image(resolution=resolution, **spec) as img_init: + img = postprocess(img_init) if img.alpha_channel: img.background_color = wand.image.Color('white') img.alpha_channel = 'background'