@@ -422,13 +422,18 @@ def text(self, string, x, y, color, *, font_name="font5x8.bin", size=1):
422422 def image (self , img ):
423423 """Set buffer to value of Python Imaging Library image. The image should
424424 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
425430 if img .mode != "1" :
426431 raise ValueError ("Image must be in mode 1." )
427432 imwidth , imheight = img .size
428- if imwidth != self . width or imheight != self . height :
433+ if imwidth != width or imheight != height :
429434 raise ValueError (
430435 "Image must be same dimensions as display ({0}x{1})." .format (
431- self . width , self . height
436+ width , height
432437 )
433438 )
434439 # Grab all the pixels from the image, faster than getpixel.
@@ -437,8 +442,8 @@ def image(self, img):
437442 for i in range (len (self .buf )):
438443 self .buf [i ] = 0
439444 # 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!
442447 if pixels [(x , y )]:
443448 self .pixel (x , y , 1 ) # only write if pixel is true
444449
0 commit comments