mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
RADICALISATION!!!!!!!!!!!!!!!!
This commit is contained in:
parent
ca26ef0673
commit
3af2682e6a
1 changed files with 39 additions and 15 deletions
|
@ -1,45 +1,69 @@
|
||||||
# You have been warned - this file is very EXTREME!
|
# You have been warned - this file is very EXTREME!
|
||||||
import discord
|
import discord
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import io
|
||||||
|
import numpy
|
||||||
|
import blend_modes
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import PIL.Image
|
import PIL.Image
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def _overlay_images(
|
||||||
|
background: PIL.Image.Image,
|
||||||
|
foreground: PIL.Image.Image,
|
||||||
|
mode=blend_modes.overlay,
|
||||||
|
opacity: float = 1.0
|
||||||
|
) -> PIL.Image.Image:
|
||||||
|
background = background.convert("RGBA")
|
||||||
|
foreground = foreground.convert("RGBA")
|
||||||
|
background.load()
|
||||||
|
foreground.load()
|
||||||
|
background_img = numpy.array(background)
|
||||||
|
background_img_float = background_img.astype(float)
|
||||||
|
foreground_img = numpy.array(foreground)
|
||||||
|
foreground_img_float = foreground_img.astype(float)
|
||||||
|
|
||||||
|
blended_img_float = mode(background_img_float, foreground_img_float, opacity)
|
||||||
|
|
||||||
|
blended_img = numpy.uint8(blended_img_float)
|
||||||
|
return PIL.Image.fromarray(blended_img)
|
||||||
|
|
||||||
|
|
||||||
def overlay_logo(img: PIL.Image.Image) -> PIL.Image.Image:
|
def overlay_logo(img: PIL.Image.Image) -> PIL.Image.Image:
|
||||||
"""Overlay the logo on an image."""
|
"""Overlay the logo on an image."""
|
||||||
logo = PIL.Image.open("assets/extreme.png", "RGBA")
|
# clone the image
|
||||||
|
img = img.copy()
|
||||||
|
logo = PIL.Image.open("assets/extreme.png")
|
||||||
|
logo.convert("RGBA")
|
||||||
|
logo.load()
|
||||||
logo = logo.resize((1024, 1024))
|
logo = logo.resize((1024, 1024))
|
||||||
img = img.resize((1024, 1024))
|
img = img.resize((1024, 1024))
|
||||||
# Use alpha overlay to merge the two
|
|
||||||
final = PIL.Image.new("RGBA", img.size)
|
img = _overlay_images(img, logo, blend_modes.darken_only)
|
||||||
final = Image.alpha_composite(final, img)
|
return img
|
||||||
final = Image.alpha_composite(final, logo)
|
|
||||||
return final
|
|
||||||
|
|
||||||
|
|
||||||
def overlay_purple(img: PIL.Image.Image) -> PIL.Image.Image:
|
def overlay_purple(img: PIL.Image.Image) -> PIL.Image.Image:
|
||||||
"""Overlay the purple on an image."""
|
"""Overlay the purple on an image."""
|
||||||
# purple_overlay_rgb = 0x440099
|
# purple_overlay_rgb = 0x440099
|
||||||
purple_overlay_rgba = (68, 0, 153, 0.5)
|
purple_overlay_rgba = (68, 0, 153)
|
||||||
# Create the overlay image
|
# Create the overlay image
|
||||||
overlay = PIL.Image.new("RGBA", img.size, purple_overlay_rgba)
|
overlay = PIL.Image.new("RGBA", img.size, purple_overlay_rgba)
|
||||||
|
|
||||||
# resize to 1024x1024
|
# resize to 1024x1024
|
||||||
img = img.resize((1024, 1024))
|
img = img.copy().resize((1024, 1024))
|
||||||
overlay = overlay.resize((1024, 1024))
|
overlay = overlay.resize((1024, 1024))
|
||||||
|
|
||||||
# Use alpha overlay to merge the two
|
img = _overlay_images(img, overlay)
|
||||||
final = PIL.Image.new("RGBA", img.size)
|
return img
|
||||||
final = Image.alpha_composite(final, img)
|
|
||||||
final = Image.alpha_composite(final, overlay)
|
|
||||||
return final
|
|
||||||
|
|
||||||
|
|
||||||
def extremify(img: PIL.Image.Image) -> PIL.Image.Image:
|
def extremify(img: PIL.Image.Image) -> PIL.Image.Image:
|
||||||
"""Apply the EXTREME effect to an image."""
|
"""Apply the EXTREME effect to an image."""
|
||||||
img = overlay_logo(img)
|
|
||||||
img = overlay_purple(img)
|
img = overlay_purple(img)
|
||||||
|
img = overlay_logo(img)
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +81,7 @@ class Extremism(commands.Cog):
|
||||||
# Download the image
|
# Download the image
|
||||||
_img_bytes = await image.read()
|
_img_bytes = await image.read()
|
||||||
# Open the image
|
# Open the image
|
||||||
img = PIL.Image.open(io.BytesIO(_img_bytes), "RGBA")
|
img = PIL.Image.open(io.BytesIO(_img_bytes))
|
||||||
# Apply the EXTREME effect
|
# Apply the EXTREME effect
|
||||||
img = await asyncio.to_thread(extremify, img)
|
img = await asyncio.to_thread(extremify, img)
|
||||||
# Save the image
|
# Save the image
|
||||||
|
|
Loading…
Reference in a new issue