75 lines
2.6 KiB
Python
75 lines
2.6 KiB
Python
"""
|
|
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, ImageDraw
|
|
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
|
|
|
|
FILENAME = "blinka.png"
|
|
|
|
width = display.width
|
|
height = display.height
|
|
|
|
image = Image.new('RGB', (width, height))
|
|
|
|
# Get drawing object to draw on image.
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
image = Image.open(FILENAME)
|
|
|
|
# Scale the image to the smaller screen dimension
|
|
image_ratio = image.width / image.height
|
|
screen_ratio = width / height
|
|
if screen_ratio < image_ratio:
|
|
scaled_width = image.width * height // image.height
|
|
scaled_height = height
|
|
else:
|
|
scaled_width = width
|
|
scaled_height = image.height * width // image.width
|
|
image = image.resize((scaled_width, scaled_height), Image.BICUBIC)
|
|
|
|
# Crop and center the image
|
|
x = scaled_width // 2 - width // 2
|
|
y = scaled_height // 2 - height // 2
|
|
image = image.crop((x, y, x + width, y + height))
|
|
|
|
# Display image.
|
|
display.image(image)
|
|
display.display()
|