Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = python-escpos
url = https://github.com/python-escpos/python-escpos
description = Python library to manipulate ESC/POS Printers
long_description = file: README.rst
long_description_content_type = text/x-rst
license = MIT
license_file = LICENSE
author = python-escpos developers
Expand Down
10 changes: 5 additions & 5 deletions src/escpos/escpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ def _read(self):
def image(
self,
img_source,
high_density_vertical=True,
high_density_horizontal=True,
impl="bitImageRaster",
fragment_height=960,
center=False,
high_density_vertical: bool = True,
high_density_horizontal: bool = True,
impl: str = "bitImageRaster",
fragment_height: int = 960,
center: bool = False,
) -> None:
"""Print an image.

Expand Down
15 changes: 8 additions & 7 deletions src/escpos/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


import math
from typing import Union

from PIL import Image, ImageOps

Expand All @@ -22,7 +23,7 @@ class EscposImage(object):
PIL, rather than spend CPU cycles looping over pixels.
"""

def __init__(self, img_source):
def __init__(self, img_source: Union[Image.Image, str]):
"""Load in an image.

:param img_source: PIL.Image, or filename to load one from.
Expand All @@ -48,23 +49,23 @@ def __init__(self, img_source):
self._im = im.convert("1")

@property
def width(self):
def width(self) -> int:
"""Return width of image in pixels."""
width_pixels, _ = self._im.size
return width_pixels

@property
def width_bytes(self):
def width_bytes(self) -> int:
"""Return width of image if you use 8 pixels per byte and 0-pad at the end."""
return (self.width + 7) >> 3

@property
def height(self):
def height(self) -> int:
"""Height of image in pixels."""
_, height_pixels = self._im.size
return height_pixels

def to_column_format(self, high_density_vertical=True):
def to_column_format(self, high_density_vertical: bool = True):
"""Extract slices of an image as equal-sized blobs of column-format data.

:param high_density_vertical: Printed line height in dots
Expand All @@ -85,7 +86,7 @@ def to_raster_format(self):
"""Convert image to raster-format binary."""
return self._im.tobytes()

def split(self, fragment_height):
def split(self, fragment_height: int):
"""Split an image into multiple fragments after fragment_height pixels.

:param fragment_height: height of fragment
Expand All @@ -102,7 +103,7 @@ def split(self, fragment_height):
fragments.append(self.img_original.crop(box))
return fragments

def center(self, max_width):
def center(self, max_width: int) -> None:
"""Center image in place.

:param: Maximum width in order to deduce x offset for centering
Expand Down