diff --git a/__pycache__/cat.cpython-39.pyc b/__pycache__/cat.cpython-39.pyc index 34c7db4..3b21e8a 100644 Binary files a/__pycache__/cat.cpython-39.pyc and b/__pycache__/cat.cpython-39.pyc differ diff --git a/cat.py b/cat.py index 63e448b..0a1f0ef 100755 --- a/cat.py +++ b/cat.py @@ -6,12 +6,11 @@ from PIL import Image import urllib.request from io import BytesIO -def cat(h, w): +def cat(w, h): url = f'https://cataas.com/cat?width={w}&height={h}' resp = urllib.request.urlopen(url) im_data = resp.read() im = Image.open(BytesIO(im_data)) - im.show() return im if __name__ == "__main__": diff --git a/pixelflut.py b/pixelflut.py index 114e80a..c918225 100755 --- a/pixelflut.py +++ b/pixelflut.py @@ -8,13 +8,6 @@ import numpy as np from PIL import Image from cat import cat -# open image to be sent -image = sys.argv[1] -im = Image.open(image) - -pixels = list(im.getdata()) -width, height = im.size -pixels = [pixels[i * width:(i + 1) * width] for i in range(0,height)] HOST, PORT = "px.oeinf.de", 1234 @@ -36,6 +29,17 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: received = str(sock.recv(1024), "utf-8") sizew = int(received.split(" ")[1]) sizeh = int(received.split(" ")[2]) + + # open image to be sent or query a cat image + if sys.argv[1] == 'cat': + im = cat(sizew,sizeh) + else: + image = sys.argv[1] + im = Image.open(image) + + pixels = list(im.getdata()) + width, height = im.size + pixels = [pixels[i * width:(i + 1) * width] for i in range(0,height)] # create list of stuff and shuffle if requested widthlist = list(range(0 + startw,min(int(sizew),(width+startw))))