mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +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:
		
				
					committed by
					
						
						Patrick Kanzler
					
				
			
			
				
	
			
			
			
						parent
						
							5bf2636753
						
					
				
				
					commit
					c4dd4f2960
				
			@@ -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:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user