Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 7bf8b15

Browse files
committed
Support image resizing
1 parent fc7adc2 commit 7bf8b15

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Adafruit_Thermal.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,23 @@ def printBitmap(self, w, h, bitmap, LaaT=False, justify=False):
561561
# For any other behavior (scale, B&W threshold, etc.), use
562562
# the Imaging Library to perform such operations before
563563
# passing the result to this function.
564-
def printImage(self, image_file, LaaT=False, justify=False):
564+
def printImage(self, image_file, LaaT=False, justify=False, resize=False):
565565
from PIL import Image
566566
# image = Image.open(image_file)
567567
image = image_file
568568
if image.mode != '1':
569569
image = image.convert('1')
570570

571-
width = image.size[0]
572-
height = image.size[1]
571+
width, height = image.size
572+
if resize:
573+
# if non-float (True, 1): set image to 100% print width
574+
# if float: interpret as fraction (.5 => 50%)
575+
desiredWidth = 384
576+
if type(resize) is float: desiredWidth *= max(0, min(resize, 1))
577+
width, height = [
578+
math.floor(desiredWidth),
579+
math.floor(desiredWidth * height / width)]
580+
image = image.resize([width, height])
573581
if width > 384:
574582
width = 384
575583
rowBytes = math.floor((width + 7) / 8)

0 commit comments

Comments
 (0)