Skip to content

Commit

Permalink
Merge pull request #32 from makermelissa/master
Browse files Browse the repository at this point in the history
Added Pillow Image drawing example
  • Loading branch information
makermelissa committed Oct 22, 2019
2 parents 8d6209b + 0846fe0 commit 81caa63
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions examples/epd_pillow_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Image resizing and drawing using the Pillow Library. For the image, check out the
associated Adafruit Learn guide at:
https://learn.adafruit.com/adafruit-eink-display-breakouts/python-code
Written by Melissa LeBlanc-Williams for Adafruit Industries
"""

import digitalio
import busio
import board
from PIL import Image
from adafruit_epd.il0373 import Adafruit_IL0373
from adafruit_epd.il91874 import Adafruit_IL91874 # pylint: disable=unused-import
from adafruit_epd.il0398 import Adafruit_IL0398 # pylint: disable=unused-import
from adafruit_epd.ssd1608 import Adafruit_SSD1608 # pylint: disable=unused-import
from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import


# create the spi device and pins we will need
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
ecs = digitalio.DigitalInOut(board.CE0)
dc = digitalio.DigitalInOut(board.D22)
srcs = None
rst = digitalio.DigitalInOut(board.D27)
busy = digitalio.DigitalInOut(board.D17)

# give them all to our driver
#display = Adafruit_SSD1608(200, 200, spi, # 1.54" HD mono display
#display = Adafruit_SSD1675(122, 250, spi, # 2.13" HD mono display
#display = Adafruit_IL91874(176, 264, spi, # 2.7" Tri-color display
#display = Adafruit_IL0373(152, 152, spi, # 1.54" Tri-color display
#display = Adafruit_IL0373(128, 296, spi, # 2.9" Tri-color display
#display = Adafruit_IL0398(400, 300, spi, # 4.2" Tri-color display
display = Adafruit_IL0373(104, 212, spi, # 2.13" Tri-color display
cs_pin=ecs, dc_pin=dc, sramcs_pin=srcs,
rst_pin=rst, busy_pin=busy)

# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines!
#display.set_black_buffer(1, False)
#display.set_color_buffer(1, False)

display.rotation = 1

image = Image.open("blinka.png")

# Scale the image to the smaller screen dimension
image_ratio = image.width / image.height
screen_ratio = display.width / display.height
if screen_ratio < image_ratio:
scaled_width = image.width * display.height // image.height
scaled_height = display.height
else:
scaled_width = display.width
scaled_height = image.height * display.width // image.width
image = image.resize((scaled_width, scaled_height), Image.BICUBIC)

# Crop and center the image
x = scaled_width // 2 - display.width // 2
y = scaled_height // 2 - display.height // 2
image = image.crop((x, y, x + display.width, y + display.height))

# Display image.
display.image(image)
display.display()

0 comments on commit 81caa63

Please sign in to comment.