@@ -422,13 +422,18 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1):
422
422
def image (self , img ):
423
423
"""Set buffer to value of Python Imaging Library image. The image should
424
424
be in 1 bit mode and a size equal to the display size."""
425
+ # determine our effective width/height, taking rotation into account
426
+ width = self .width
427
+ height = self .height
428
+ if self .rotation == 1 or self .rotation == 3 :
429
+ width , height = height , width
425
430
if img .mode != "1" :
426
431
raise ValueError ("Image must be in mode 1." )
427
432
imwidth , imheight = img .size
428
- if imwidth != self . width or imheight != self . height :
433
+ if imwidth != width or imheight != height :
429
434
raise ValueError (
430
435
"Image must be same dimensions as display ({0}x{1})." .format (
431
- self . width , self . height
436
+ width , height
432
437
)
433
438
)
434
439
# Grab all the pixels from the image, faster than getpixel.
@@ -437,8 +442,8 @@ def image(self, img):
437
442
for i in range (len (self .buf )):
438
443
self .buf [i ] = 0
439
444
# Iterate through the pixels
440
- for x in range (self . width ): # yes this double loop is slow,
441
- for y in range (self . height ): # but these displays are small!
445
+ for x in range (width ): # yes this double loop is slow,
446
+ for y in range (height ): # but these displays are small!
442
447
if pixels [(x , y )]:
443
448
self .pixel (x , y , 1 ) # only write if pixel is true
444
449
0 commit comments