/ examples / epd_pillow_image.py
epd_pillow_image.py
 1  """
 2  Image resizing and drawing using the Pillow Library. For the image, check out the
 3  associated Adafruit Learn guide at:
 4  https://learn.adafruit.com/adafruit-eink-display-breakouts/python-code
 5  
 6  Written by Melissa LeBlanc-Williams for Adafruit Industries
 7  """
 8  
 9  import digitalio
10  import busio
11  import board
12  from PIL import Image
13  from adafruit_epd.il0373 import Adafruit_IL0373
14  from adafruit_epd.il91874 import Adafruit_IL91874  # pylint: disable=unused-import
15  from adafruit_epd.il0398 import Adafruit_IL0398  # pylint: disable=unused-import
16  from adafruit_epd.ssd1608 import Adafruit_SSD1608  # pylint: disable=unused-import
17  from adafruit_epd.ssd1675 import Adafruit_SSD1675  # pylint: disable=unused-import
18  
19  
20  # create the spi device and pins we will need
21  spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
22  ecs = digitalio.DigitalInOut(board.CE0)
23  dc = digitalio.DigitalInOut(board.D22)
24  srcs = None
25  rst = digitalio.DigitalInOut(board.D27)
26  busy = digitalio.DigitalInOut(board.D17)
27  
28  # give them all to our driver
29  # display = Adafruit_SSD1608(200, 200,        # 1.54" HD mono display
30  # display = Adafruit_SSD1675(122, 250,        # 2.13" HD mono display
31  # display = Adafruit_IL91874(176, 264,        # 2.7" Tri-color display
32  # display = Adafruit_IL0373(152, 152,         # 1.54" Tri-color display
33  # display = Adafruit_IL0373(128, 296,         # 2.9" Tri-color display
34  # display = Adafruit_IL0398(400, 300,         # 4.2" Tri-color display
35  display = Adafruit_IL0373(
36      104,
37      212,  # 2.13" Tri-color display
38      spi,
39      cs_pin=ecs,
40      dc_pin=dc,
41      sramcs_pin=srcs,
42      rst_pin=rst,
43      busy_pin=busy,
44  )
45  
46  # IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines!
47  # display.set_black_buffer(1, False)
48  # display.set_color_buffer(1, False)
49  
50  display.rotation = 1
51  
52  image = Image.open("blinka.png")
53  
54  # Scale the image to the smaller screen dimension
55  image_ratio = image.width / image.height
56  screen_ratio = display.width / display.height
57  if screen_ratio < image_ratio:
58      scaled_width = image.width * display.height // image.height
59      scaled_height = display.height
60  else:
61      scaled_width = display.width
62      scaled_height = image.height * display.width // image.width
63  image = image.resize((scaled_width, scaled_height), Image.BICUBIC)
64  
65  # Crop and center the image
66  x = scaled_width // 2 - display.width // 2
67  y = scaled_height // 2 - display.height // 2
68  image = image.crop((x, y, x + display.width, y + display.height))
69  
70  # Display image.
71  display.image(image)
72  display.display()