From b54d59176e904cdbde1291d73570cf8c86175a09 Mon Sep 17 00:00:00 2001 From: hundredrab Date: Mon, 22 Oct 2018 11:49:26 +0530 Subject: Add more spookifications. --- bot/resources/bat-clipart.png | Bin 0 -> 12313 bytes bot/resources/bloody-pentagram.png | Bin 0 -> 7006 bytes bot/resources/spookifications.py | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 bot/resources/bat-clipart.png create mode 100644 bot/resources/bloody-pentagram.png (limited to 'bot/resources') diff --git a/bot/resources/bat-clipart.png b/bot/resources/bat-clipart.png new file mode 100644 index 00000000..7df26ba9 Binary files /dev/null and b/bot/resources/bat-clipart.png differ diff --git a/bot/resources/bloody-pentagram.png b/bot/resources/bloody-pentagram.png new file mode 100644 index 00000000..4e6da07a Binary files /dev/null and b/bot/resources/bloody-pentagram.png differ diff --git a/bot/resources/spookifications.py b/bot/resources/spookifications.py index 880b24e7..43e8b038 100644 --- a/bot/resources/spookifications.py +++ b/bot/resources/spookifications.py @@ -1,5 +1,11 @@ +import logging +from random import choice, randint + +from PIL import Image from PIL import ImageOps +log = logging.getLogger() + def inversion(im): """Inverts an image. @@ -9,3 +15,39 @@ def inversion(im): im = im.convert('RGB') inv = ImageOps.invert(im) return inv + + +def pentagram(im): + """Adds pentagram to image.""" + im = im.convert('RGB') + wt, ht = im.size + penta = Image.open('bot/resources/bloody-pentagram.png') + penta = penta.resize((wt, ht)) + im.paste(penta, (0, 0), penta) + return im + + +def bat(im): + """Adds a bat silhoutte to the image. + + The bat silhoutte is of a size at least one-fifths that of the original + image and may be rotated upto 90 degrees anti-clockwise.""" + im = im.convert('RGB') + wt, ht = im.size + bat = Image.open('bot/resources/bat-clipart.png') + bat_size = randint(wt//5, wt) + rot = randint(0, 90) + bat = bat.resize((bat_size, bat_size)) + bat = bat.rotate(rot) + x = randint(0, wt-bat_size) + y = randint(0, wt-bat_size) + im.paste(bat, (x, y), bat) + return im + + +def get_random_effect(im): + """Randomly selects and applies an effect.""" + effects = [inversion, pentagram, bat] + effect = choice(effects) + log.info("Spookyavatar's chosen effect:" + str(effect)) + return effect(im) -- cgit v1.2.3