Full completed project
This commit is contained in:
53
testing/picture-test/client.py
Normal file
53
testing/picture-test/client.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import socketio
|
||||
|
||||
sio = socketio.Client()
|
||||
|
||||
# http://localhost:9999
|
||||
def start_client(sio, url):
|
||||
print("starting socketio client...")
|
||||
try:
|
||||
if not url:
|
||||
url = "http://localhost:9999"
|
||||
sio.connect(url)
|
||||
print("socketio client online!")
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
print("socketio client failed to connect!")
|
||||
|
||||
def stop_client(sio):
|
||||
print("stopping socketio client...")
|
||||
sio.disconnect()
|
||||
|
||||
def send_picture():
|
||||
image_path = "images/profile.jpg"
|
||||
with open(image_path, "rb") as image:
|
||||
image_data = image.read()
|
||||
data = {'image_data': image_data}
|
||||
print("sending image")
|
||||
sio.emit("recv_image", data)
|
||||
|
||||
@sio.event
|
||||
def recv_image(sid, data=None):
|
||||
image_data = data['image_data']
|
||||
#base_image_path = "data/images/base-image.jpg"
|
||||
#save_path = "data/images/test.jpg"
|
||||
base_image_path = "images/base-image.jpg"
|
||||
save_path = "images/im1-client.jpg"
|
||||
|
||||
try:
|
||||
Image.open(base_image_path)
|
||||
except:
|
||||
base_image = Image.new(mode="RGB", size=(200,200))
|
||||
base_image.save(base_image_path)
|
||||
|
||||
with Image.open(base_image_path) as recieved:
|
||||
recieved.data = image_data
|
||||
recieved.save(save_path)
|
||||
|
||||
def main():
|
||||
if start_client(sio, None):
|
||||
send_picture()
|
||||
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user