-
Notifications
You must be signed in to change notification settings - Fork 5
/
SendImage.py
68 lines (46 loc) · 1.36 KB
/
SendImage.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import base64
import binascii
from urllib.request import urlopen
def main():
#with open ('test.png', 'rb') as f:
#data = f.read()
#with open ('picture_out.png', 'wb') as f:
# f.write(data)
url = "http://i50.tinypic.com/34g8vo5.jpg"
data = urlopen(url).read()
w = split_by_length(data, 512)
print("Length of data: " + str(len(data)))
print("Number of packets required to send all the data = " + str( int((len(data)/512) ) ) )
print(len(data) % 512 )
print(w[0])
print(type(w[0]))
'''
f = open("test.png", "rb")
##b = os.path.getsize("test.png")
ima = f.read()
f.close()
imgdata = base64.b64decode(ima)
filename = 'some_image.png' # I assume you have a way of picking unique filenames
with open(filename, 'wb') as f:
f.write(imgdata)
'''
'''
f = open("test.png", "rb")
b = os.path.getsize("test.png")
ima = f.read(b)
ima = base64.b64decode(ima)
w = split_by_length(ima,512)
print(w)
##print(ima.decode('utf-32'))
'''
def split_by_len(text, chunksize):
return [text[i:(i+chunksize)] for i in range(len(text)-chunksize+1)]
def split_by_length(s,block_size):
w=[]
n=len(s)
for i in range(0,n,block_size):
w.append(s[i:i+block_size])
return w
if __name__ == '__main__':
main()