Add random cat images (untested!!)
This commit is contained in:
1 parent
1e9647f781
commit
80f871fb20
3 files changed
+12
-9
No files matched your search
Binary file not shown.
@@ -6,12 +6,11 @@ from PIL import Image
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
def cat(h, w):
|
def cat(w, h):
|
||||||
url = f'https://cataas.com/cat?width={w}&height={h}'
|
url = f'https://cataas.com/cat?width={w}&height={h}'
|
||||||
resp = urllib.request.urlopen(url)
|
resp = urllib.request.urlopen(url)
|
||||||
im_data = resp.read()
|
im_data = resp.read()
|
||||||
im = Image.open(BytesIO(im_data))
|
im = Image.open(BytesIO(im_data))
|
||||||
im.show()
|
|
||||||
return im
|
return im
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
+11
-7
@@ -8,13 +8,6 @@ import numpy as np
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from cat import cat
|
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
|
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")
|
received = str(sock.recv(1024), "utf-8")
|
||||||
sizew = int(received.split(" ")[1])
|
sizew = int(received.split(" ")[1])
|
||||||
sizeh = int(received.split(" ")[2])
|
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
|
# create list of stuff and shuffle if requested
|
||||||
widthlist = list(range(0 + startw,min(int(sizew),(width+startw))))
|
widthlist = list(range(0 + startw,min(int(sizew),(width+startw))))
|
||||||
|
|||||||
Reference in new issue
Block a user