1
0
mirror of https://github.com/python-escpos/python-escpos synced 2025-09-13 09:09:58 +00:00

Added ImageWidthError and its implementation (#226)

* Added ImageWidthError and its implementation

* Added unit tests for ImageWidthError

* Parse max_width to int before compare
This commit is contained in:
Romain Porte
2017-05-23 15:13:28 +02:00
committed by Patrick Kanzler
parent 5bf2636753
commit c4dd4f2960
3 changed files with 51 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ from .constants import TXT_STYLE
from .exceptions import BarcodeTypeError, BarcodeSizeError, TabPosError
from .exceptions import CashDrawerError, SetVariableError, BarcodeCodeError
from .exceptions import ImageWidthError
from .magicencode import MagicEncode
@@ -99,6 +100,17 @@ class Escpos(object):
"""
im = EscposImage(img_source)
try:
max_width = int(self.profile.profile_data['media']['width']['pixels'])
if im.width > max_width:
raise ImageWidthError('{} > {}'.format(im.width, max_width))
except KeyError:
# If the printer's pixel width is not known, print anyways...
pass
except ValueError:
# If the max_width cannot be converted to an int, print anyways...
pass
if im.height > fragment_height:
fragments = im.split(fragment_height)
for fragment in fragments: