Skip to content

Commit

Permalink
Make image DPI configurable
Browse files Browse the repository at this point in the history
Fixes: #206
  • Loading branch information
WhyNotHugo committed Sep 20, 2023
1 parent 8ed1aa4 commit 8e09fc7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions barcode/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Callbacks(TypedDict):
Image = ImageDraw = ImageFont = None


def mm2px(mm, dpi=300):
def mm2px(mm, dpi: int):
return (mm * dpi) / 25.4


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

def __init__(self, format="PNG", mode="RGB") -> None:
def __init__(self, format="PNG", mode="RGB", dpi=300) -> None:
"""Initialise a new write instance.
:params format: The file format for the generated image. This parameter can
take any value that Pillow accepts.
:params mode: The colour-mode for the generated image. Set this to RGBA if
you wish to use colours with transparency.
"""
BaseWriter.__init__(
self, self._init, self._paint_module, self._paint_text, self._finish
super().__init__(
self._init,
self._paint_module,
self._paint_text,
self._finish,
)
self.format = format
self.mode = mode
self.dpi = 300
self.dpi = dpi
self._image = None
self._draw = None

Expand Down

0 comments on commit 8e09fc7

Please sign in to comment.