@@ -372,13 +372,18 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1):
372
372
def image (self , img ):
373
373
"""Set buffer to value of Python Imaging Library image. The image should
374
374
be in 1 bit mode and a size equal to the display size."""
375
+ # determine our effective width/height, taking rotation into account
376
+ width = self .width
377
+ height = self .height
378
+ if self .rotation == 1 or self .rotation == 3 :
379
+ width , height = height , width
375
380
if img .mode != "1" :
376
381
raise ValueError ("Image must be in mode 1." )
377
382
imwidth , imheight = img .size
378
- if imwidth != self . width or imheight != self . height :
383
+ if imwidth != width or imheight != height :
379
384
raise ValueError (
380
385
"Image must be same dimensions as display ({0}x{1})." .format (
381
- self . width , self . height
386
+ width , height
382
387
)
383
388
)
384
389
# Grab all the pixels from the image, faster than getpixel.
@@ -387,8 +392,8 @@ def image(self, img):
387
392
for i in range (len (self .buf )):
388
393
self .buf [i ] = 0
389
394
# Iterate through the pixels
390
- for x in range (self . width ): # yes this double loop is slow,
391
- for y in range (self . height ): # but these displays are small!
395
+ for x in range (width ): # yes this double loop is slow,
396
+ for y in range (height ): # but these displays are small!
392
397
if pixels [(x , y )]:
393
398
self .pixel (x , y , 1 ) # only write if pixel is true
394
399
0 commit comments