Skip to content

Commit

Permalink
Delay import of PIL-dependent modules
Browse files Browse the repository at this point in the history
The pyhanko.stamp module now defers importing the modules for barcode
and image support until it needs them. See issue #13.
  • Loading branch information
MatthiasValvekens committed Apr 14, 2021
1 parent 984a3df commit a8793ba
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyhanko/stamp.py
Expand Up @@ -16,8 +16,6 @@
import qrcode
import tzlocal

from pyhanko.pdf_utils.barcodes import PdfStreamQRImage
from pyhanko.pdf_utils.images import PdfImage
from pyhanko.pdf_utils.incremental_writer import IncrementalPdfFileWriter
from pyhanko.pdf_utils.misc import rd
from pyhanko.pdf_utils.layout import BoxSpecificationError, BoxConstraints
Expand Down Expand Up @@ -164,6 +162,7 @@ def process_entries(cls, config_dict):
if bg_spec == '__stamp__':
config_dict['background'] = STAMP_ART_CONTENT
elif isinstance(bg_spec, str):
from pyhanko.pdf_utils.images import PdfImage
from PIL import Image
img = Image.open(bg_spec)
# Setting the writer can be delayed
Expand Down Expand Up @@ -528,6 +527,7 @@ def _qr_xobject(self):
qr.add_data(self.url)
qr.make()

from pyhanko.pdf_utils.barcodes import PdfStreamQRImage
img = qr.make_image(image_factory=PdfStreamQRImage)
command_stream = img.render_command_stream()

Expand Down

0 comments on commit a8793ba

Please sign in to comment.