Skip to content

Instantly share code, notes, and snippets.

@memmam
Last active April 13, 2022 19:01
Show Gist options
  • Save memmam/d39fd9028abbdb6629fb570776b50604 to your computer and use it in GitHub Desktop.
Save memmam/d39fd9028abbdb6629fb570776b50604 to your computer and use it in GitHub Desktop.
r/Place 2022 Amogus Detection Script
# r/Place 2022 Amogus Detection Script
#
# Original script by u/DiabeticDonkey 04/03/2022, found here: https://pastebin.com/P4i8tcKG
# Revised version by u/SquidRobotFriend, 04/13/2022
import requests
from PIL import Image
from PIL.Image import Resampling
import argparse, sys
class Parser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
parser = Parser()
parser.add_argument('--input', type=str, default="https://placedata.reddit.com/data/final_place.png", help='Input for Amogus detection, can accept filename or URL. Default: URL for Reddit final canvas')
parser.add_argument('--output', type=str, default="amogus.png", help='Desired output location. Default: amogus.png')
opts = parser.parse_args()
amongs = []
amogi_types = []
amogi_found = []
amongs.append([[0, 1, 1, 9],
[6, 1, 3, 2],
[6, 1, 1, 1],
[6, 1, 1, 1],
[7, 1, 1, 1],
[5, 1, 4, 1]])
amogi_types.append("Tall Right")
amogi_found.append(0)
amongs.append([[9, 1, 1, 0],
[2, 3, 1, 6],
[1, 1, 1, 6],
[1, 1, 1, 6],
[1, 1, 1, 7],
[1, 4, 1, 5]])
amogi_types.append("Tall Left")
amogi_found.append(0)
amongs.append([[0, 1, 1, 9],
[6, 1, 3, 2],
[6, 1, 1, 1],
[6, 1, 1, 1],
[5, 1, 4, 1]])
amogi_types.append("Long Backpack Right")
amogi_found.append(0)
amongs.append([[9, 1, 1, 0],
[2, 3, 1, 6],
[1, 1, 1, 6],
[1, 1, 1, 6],
[1, 4, 1, 5]])
amogi_types.append("Long Backpack Left")
amogi_found.append(0)
amongs.append([[0, 1, 1, 9],
[6, 1, 3, 2],
[6, 1, 1, 1],
[7, 1, 1, 1],
[5, 1, 4, 1]])
amogi_types.append("Normal Right")
amogi_found.append(0)
amongs.append([[9, 1, 1, 0],
[2, 3, 1, 6],
[1, 1, 1, 6],
[1, 1, 1, 7],
[1, 4, 1, 5]])
amogi_types.append("Normal Left")
amogi_found.append(0)
amongs.append([[0, 1, 1, 9],
[6, 1, 3, 2],
[6, 1, 1, 1],
[7, 1, 8, 1],
[5, 1, 4, 1]])
amogi_types.append("Long Legs Right")
amogi_found.append(0)
amongs.append([[9, 1, 1, 0],
[2, 3, 1, 6],
[1, 1, 1, 6],
[1, 8, 1, 7],
[1, 4, 1, 5]])
amogi_types.append("Long Legs Left")
amogi_found.append(0)
amongs.append([[0, 1, 1, 9],
[6, 1, 3, 2],
[6, 1, 1, 1],
[5, 1, 4, 1]])
amogi_types.append("Mini Right")
amogi_found.append(0)
amongs.append([[9, 1, 1, 0],
[2, 3, 1, 6],
[1, 1, 1, 6],
[1, 4, 1, 5]])
amogi_types.append("Mini Left")
amogi_found.append(0)
amongs.append([[1, 1, 1],
[1, 3, 2],
[1, 1, 1],
[1, 1, 1],
[1, 4, 1]])
amogi_types.append("Backpackless Right")
amogi_found.append(0)
amongs.append([[1, 1, 1],
[2, 3, 1],
[1, 1, 1],
[1, 1, 1],
[1, 4, 1]])
amogi_types.append("Backpackless Left")
amogi_found.append(0)
amongs.append([[1, 1, 1],
[1, 3, 2],
[1, 1, 1],
[1, 4, 1]])
amogi_types.append("Mini Backpackless Right")
amogi_found.append(0)
amongs.append([[1, 1, 1],
[2, 3, 1],
[1, 1, 1],
[1, 4, 1]])
amogi_types.append("Mini Backpackless Left")
amogi_found.append(0)
def amongCheck(x, y, img, newImg, among):
pix = img.load()
newPix = newImg.load()
if x+len(among[0]) - 1 >= 2000:
return False
if y+len(among) - 1 >= 2000:
return False
Rs = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
Gs = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
Bs = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
As = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
for row in range(len(among)):
for column in range(len(among[0])):
r, g, b, a = pix[x+column,y+row]
amg = among[row][column]
if Rs[amg] == -1:
Rs[amg], Gs[amg], Bs[amg], As[amg] = r, g, b, a
else:
if amg != 0:
if Rs[amg] != r or Gs[amg] != g or Bs[amg] != b or As[amg] != a:
return False
col0 = '#%02x%02x%02x%02x' % (Rs[0], Gs[0], Bs[0], As[0])
col1 = '#%02x%02x%02x%02x' % (Rs[1], Gs[1], Bs[1], As[1])
col2 = '#%02x%02x%02x%02x' % (Rs[2], Gs[2], Bs[2], As[2])
col3 = '#%02x%02x%02x%02x' % (Rs[3], Gs[3], Bs[3], As[3])
col4 = '#%02x%02x%02x%02x' % (Rs[4], Gs[4], Bs[4], As[4])
col5 = '#%02x%02x%02x%02x' % (Rs[5], Gs[5], Bs[5], As[5])
col6 = '#%02x%02x%02x%02x' % (Rs[6], Gs[6], Bs[6], As[6])
col7 = '#%02x%02x%02x%02x' % (Rs[7], Gs[7], Bs[7], As[7])
col8 = '#%02x%02x%02x%02x' % (Rs[8], Gs[8], Bs[8], As[8])
col9 = '#%02x%02x%02x%02x' % (Rs[9], Gs[9], Bs[9], As[9])
if (col1 != col9 and col1 == col3) or ((col6 == col0 and col0 != "#-1-1-1-1") or ((col1 == col0) and (col1 == col4) or (col1 == col5))) or (col1 == col2 and col1 == col3) or ((col1 == col2 or col1 == col3) and col0 == "#-1-1-1-1") or (col1 == col4 and (col1 == col5 or col0 == "#-1-1-1-1")):
return False
for row in range(len(among)):
for column in range(len(among[0])):
amg = among[row][column]
newPix[x+column, y+row] = Rs[amg], Gs[amg], Bs[amg], As[amg]
return True
if opts.input.find('://') != -1:
input_image = requests.get(opts.input, stream=True).raw
else:
input_image = opts.input
img1 = Image.open(input_image).convert("RGBA")
newImg1 = Image.new(mode="RGBA", size=(2000,2000))
for y in range(2000):
for x in range(2000):
for i in range(len(amongs)):
if amongCheck(x, y, img1, newImg1, amongs[i]):
amogi_found[i] += 1
break
print(y)
backGround = Image.new("RGBA", (2000, 2000))
backGround.paste(img1, (0,0))
master = Image.new("RGBA", (2000, 2000))
master.paste(newImg1, (0,0))
masterPix = master.load()
bgPix = backGround.load()
for y in range(2000):
for x in range(2000):
r, g, b, a = masterPix[x, y]
if a == 0:
r, g, b, a = bgPix[x, y]
masterPix[x, y] = r, g, b, 50
total_amogi = 0
for i in range(len(amongs)):
print(amogi_types[i] + ": " + str(amogi_found[i]))
total_amogi += amogi_found[i]
print("Total Amogi Found: " + str(total_amogi))
master.save(opts.output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment