dfi-led-matrix/client_sw/images.py

38 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import time
from PIL import Image, ImageDraw, ImageFont
from matrixSender import MatrixSender
import time
import sys
from random import randint
matrix = MatrixSender(udphost="localhost", udpport=2323, img_size=(160,24*6), bitsperpixel=2)
def send_img_from_filename(imgfilename,invert=False):
background = Image.new("RGBA", matrix._img_size, MatrixSender.C_BLACK)
image = Image.open(imgfilename)
image = image.convert(mode='RGBA')
image = image.resize(matrix._img_size)
image.save('/tmp/send2.png', 'PNG')
background.paste(image, box=(0,0), mask=None)
background.save('/tmp/send.png', 'PNG')
matrix.send(background,invert)
def send_img(img):
background = Image.new("RGBA", matrix._img_size, MatrixSender.C_BLACK)
stream = io.BytesIO(img)
image = Image.open(stream)
image = image.convert(mode='RGBA')
image = image.resize(matrix._img_size)
image.save('/tmp/send2.jpeg', 'JPEG')
background.paste(image, box=(0,0), mask=None)
background.save('/tmp/send.jpeg', 'JPEG')
matrix.send(background)
if __name__ == '__main__':
if len(sys.argv)>1:
send_img_from_filename(sys.argv[1])