From a6ec6748287c86191bd134f5507da9e0429474e7 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Thu, 22 May 2014 01:08:58 -0400 Subject: [PATCH] Allow bypassing the resizing and height-cropping steps in fullimage() --- escpos/escpos.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index 2ce4c57..59884ca 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -184,19 +184,22 @@ class Escpos(object): n = n + h[i+b] im = im.point(lut) - ratio = float(width) / im.size[0] - newheight = int(ratio * im.size[1]) + if width: + ratio = float(width) / im.size[0] + newheight = int(ratio * im.size[1]) - # Resize the image - im = im.resize((width, newheight), Image.ANTIALIAS) - if im.size[1] > max_height: + # Resize the image + im = im.resize((width, newheight), Image.ANTIALIAS) + + if max_height and im.size[1] > max_height: im = im.crop((0, 0, im.size[0], max_height)) # Divide into bands bandsize = 255 current = 0 while current < im.size[1]: - self.image(im.crop((0, current, width, min(im.size[1], current + bandsize)))) + self.image(im.crop((0, current, width or im.size[0], + min(im.size[1], current + bandsize)))) current += bandsize def direct_image(self, image):