I am trying to resize an image to display on my OLED device.
My image I want to display is:
Currently, my OLED display only shows a fraction of the image:
Based on How to resize image?, I added new_img = img.resize((128,128))
to my script to resize the image. The same fraction of the image however appears on the screen. When I tried to enter a lower image size for the resize argument (64x64), terminal prints:
pi@raspberrypi:~/project $ python colors.py --display ssd1351 --width 128 --height 128 --interface spi --spi-bus-speed 16000000 --gpio-data-command 20
Version: luma.oled 2.3.1 (luma.core 1.3.0)
Display: ssd1351
Interface: spi
Dimensions: 128 x 128
------------------------------------------------------------
Traceback (most recent call last):
File "colors.py", line 87, in <module>
main()
File "colors.py", line 30, in main
device.display(new_img)
File "/usr/local/lib/python2.7/dist-packages/luma/oled/device.py", line 371, in display
assert(image.size == self.size)
AssertionError
Any ideas on how I can resize the image properly for the OLED display?
My full script is:
#!/usr/bin/env python
import math
import time
import random
import os.path
from demo_opts import get_device
from luma.core.render import canvas
from PIL import Image
def main():
img_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), 'plot.jpg'))
img = Image.open(img_path) \
.transform(device.size, Image.AFFINE, (1, 0, 0, 0, 1, 0), Image.BILINEAR) \
.convert(device.mode)
new_img = img.resize((128,128))
while True:
# Image display
device.display(new_img)
time.sleep(5)
if __name__ == "__main__":
try:
device = get_device()
main()
except KeyboardInterrupt:
pass