...
 
Commits (3)
......@@ -8,9 +8,14 @@ systemctl enable imageshow.service
```
# Usage
display image:
`curl -XPOST http://host/ -d @file.svg`
`curl -XPOST http://host/ --data @file.svg`
show last image:
`curl -XPOST http://host/ --data-binary @file.jpg`
display collor:
`curl -XPOST http://host/fill --data 'r=255&g=1&b=0&a=255'`
show current image:
`firefox http://host/`
turn display off:
......
......@@ -12,9 +12,9 @@ from subprocess import Popen, PIPE, STDOUT
from PIL import Image
from io import BytesIO
from os import path, chdir
from urllib.parse import parse_qs
FRAMEBUFFER = 'fb0'
PNG_PATH = '/tmp/screen.png'
RSVGCONVERT = '/usr/bin/rsvg-convert'
RSVGCONVERT_ARGS = ['-u', '--keep-image-data']
BLANKINGCMD = '/usr/bin/vcgencmd'
......@@ -26,8 +26,17 @@ class Server(BaseHTTPRequestHandler):
self.send_response(200)
self.send_header('Content-type', 'image/png')
self.end_headers()
with open(PNG_PATH, 'rb') as file:
self.wfile.write(file.read())
fh = open('/dev/' + FRAMEBUFFER, 'rb')
image = Image.frombytes('RGBA', (buf_width, buf_height), fh.read(), 'raw').convert('RGBA')
image.save('/tmp/test.png', format='PNG')
fh.close()
b,g,r,a = image.split()
new_image = Image.merge("RGBA", (r,g,b,a))
pngBytes = BytesIO()
new_image.save(pngBytes, format='PNG')
self.wfile.write(pngBytes.getvalue())
def do_POST(self):
if self.path == '/':
......@@ -42,6 +51,22 @@ class Server(BaseHTTPRequestHandler):
display_on()
self.send_response(204)
self.end_headers()
elif self.path == '/fill':
display_on()
length = int(self.headers['content-length'])
postvars = parse_qs(self.rfile.read(length))
print(postvars)
buffer = bytearray()
buffer.extend(struct.pack('B', int(postvars[b'b'][0])))
buffer.extend(struct.pack('B', int(postvars[b'g'][0])))
buffer.extend(struct.pack('B', int(postvars[b'r'][0])))
buffer.extend(struct.pack('B', int(postvars[b'a'][0])))
buffer = buffer * (buf_width * buf_height)
with open('/dev/' + FRAMEBUFFER, 'wb') as f:
f.write(buffer)
self.send_response(204)
self.end_headers()
else:
self.send_response(404)
self.send_header('Content-type', 'text/plain')
......@@ -73,7 +98,7 @@ def process(svg, http):
return False
if not check_size(image, http):
return False
image.save(PNG_PATH, format='PNG')
image.save(last_image, format='PNG')
image = convert(image)
draw(image)
print('done')
......@@ -144,6 +169,7 @@ def init():
buf_width = 0
buf_height = 0
last_image = BytesIO()
def run(server_class=HTTPServer, handler_class=Server, port=80):
global buf_width, buf_height
fbsize = open('/sys/class/graphics/' + FRAMEBUFFER + '/virtual_size', 'r')
......@@ -171,4 +197,4 @@ if __name__ == "__main__":
else:
run()
except KeyboardInterrupt as e:
print(e)
\ No newline at end of file
print(e)