aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/halloween/spookifications.py
blob: 11f69850889b29ddd6a3c20377e53d02ac40b5a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import logging
from random import choice, randint

from PIL import Image
from PIL import ImageOps

log = logging.getLogger()


def inversion(im: Image) -> Image:
    """
    Inverts the image.

    Returns an inverted image when supplied with an Image object.
    """
    im = im.convert('RGB')
    inv = ImageOps.invert(im)
    return inv


def pentagram(im: Image) -> Image:
    """Adds pentagram to the image."""
    im = im.convert('RGB')
    wt, ht = im.size
    penta = Image.open('bot/resources/halloween/bloody-pentagram.png')
    penta = penta.resize((wt, ht))
    im.paste(penta, (0, 0), penta)
    return im


def bat(im: Image) -> Image:
    """
    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
    up to 90 degrees anti-clockwise.
    """
    im = im.convert('RGB')
    wt, ht = im.size
    bat = Image.open('bot/resources/halloween/bat-clipart.png')
    bat_size = randint(wt//10, wt//7)
    rot = randint(0, 90)
    bat = bat.resize((bat_size, bat_size))
    bat = bat.rotate(rot)
    x = randint(wt-(bat_size * 3), wt-bat_size)
    y = randint(10, bat_size)
    im.paste(bat, (x, y), bat)
    im.paste(bat, (x + bat_size, y + (bat_size // 4)), bat)
    im.paste(bat, (x - bat_size, y - (bat_size // 2)), bat)
    return im


def get_random_effect(im: Image) -> Image:
    """Randomly selects and applies an effect."""
    effects = [inversion, pentagram, bat]
    effect = choice(effects)
    log.info("Spookyavatar's chosen effect: " + effect.__name__)
    return effect(im)