Skip to content

Commit 8e09fc7

Browse files
committed
Make image DPI configurable
Fixes: #206
1 parent 8ed1aa4 commit 8e09fc7

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

barcode/writer.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Callbacks(TypedDict):
4444
Image = ImageDraw = ImageFont = None
4545

4646

47-
def mm2px(mm, dpi=300):
47+
def mm2px(mm, dpi: int):
4848
return (mm * dpi) / 25.4
4949

5050

@@ -409,20 +409,23 @@ class ImageWriter(BaseWriter): # type: ignore[no-redef]
409409
mode: str
410410
dpi: int
411411

412-
def __init__(self, format="PNG", mode="RGB") -> None:
412+
def __init__(self, format="PNG", mode="RGB", dpi=300) -> None:
413413
"""Initialise a new write instance.
414414
415415
:params format: The file format for the generated image. This parameter can
416416
take any value that Pillow accepts.
417417
:params mode: The colour-mode for the generated image. Set this to RGBA if
418418
you wish to use colours with transparency.
419419
"""
420-
BaseWriter.__init__(
421-
self, self._init, self._paint_module, self._paint_text, self._finish
420+
super().__init__(
421+
self._init,
422+
self._paint_module,
423+
self._paint_text,
424+
self._finish,
422425
)
423426
self.format = format
424427
self.mode = mode
425-
self.dpi = 300
428+
self.dpi = dpi
426429
self._image = None
427430
self._draw = None
428431

0 commit comments

Comments
 (0)