Skip to content

Instantly share code, notes, and snippets.

@cthpw103
Created August 5, 2019 23:06
Show Gist options
  • Save cthpw103/3ad38da2fa83ce65fa5e9ae549d80737 to your computer and use it in GitHub Desktop.
Save cthpw103/3ad38da2fa83ce65fa5e9ae549d80737 to your computer and use it in GitHub Desktop.
pxls to image
import urllib.request
from PIL import Image
import json
import time
def hex2rgb(hexcode):
return tuple(int(hexcode[i:i+2], 16) for i in (0, 2 ,4))
def screenshot(server="https://pxls.space", outputpath="./screenshot.png"):
reqopen = urllib.request.urlopen(server+"/info")
info = json.load(reqopen)
print(info["palette"])
palette = info["palette"]
height = info["height"]
width = info["width"]
img = Image.new("RGB", [width,height])
pixelsNew = img.load()
request = urllib.request.Request(server+"/boarddata")
request.add_header("Cookie", "pxls-agegate=1")
board = list(urllib.request.urlopen(request).read())
for x in range(0, width):
for y in range(0, height):
pixelsNew[x, y] = hex2rgb(palette[board[x + y * width]].lstrip('#'))
img.save(outputpath)
img.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment