-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_image.py
More file actions
52 lines (41 loc) · 1.18 KB
/
send_image.py
File metadata and controls
52 lines (41 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Send image
Sends a 128x64 1bpp image to the pumpkin. Can be animated or static.
"""
# could I make this better with argparse? sure?
# will I? hahahahahahhaha no
from PIL import Image
from PIL.GifImagePlugin import GifImageFile
path = "doot.gif" # testing
path = "doot.bmp"
path = "images/smiley.bmp"
image = Image.open(path)
DIM_X = 128
DIM_Y = 64
image_bytes = []
num_frames = 1
if isinstance(image, GifImageFile):
num_frames = image.n_frames
image_bytes.append(1) # mode
image_bytes.append(25) # animFrameTime
image_bytes.append(num_frames) # num frames
for frame in range(num_frames):
if isinstance(image, GifImageFile):
image.seek(frame)
# bytes will read left to right on each row
# top to bottom
pa = image.load()
for y in range(64):
for x in range(0, 128, 8):
byte = 0
for b in range(8):
coord = (x + b, y)
val = pa[coord] & 1 # only want one 1 bit
byte = byte << 1
byte |= val
image_bytes.append(byte)
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('10.1.1.190', 8001))
s.send(bytearray(image_bytes))
s.close()