37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
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])
|