async def deepfry(img: BinaryIO) -> BinaryIO: """Deepfry logic!""" colours = ( ((254, 0, 2), (255, 255, 15)), ((36, 113, 229), (255, ) * 3), ) # Crush image to hell and back img = img.convert("RGB") width, height = img.width, img.height img = img.resize((int(width**0.75), int(height**0.75)), resample=Image.LANCZOS) img = img.resize((int(width**0.88), int(height**0.88)), resample=Image.BILINEAR) img = img.resize((int(width**0.9), int(height**0.9)), resample=Image.BICUBIC) img = img.resize((width, height), resample=Image.BICUBIC) # Generate colour overlay overlay = img.split()[0] overlay = ImageEnhance.Contrast(overlay).enhance(2.0) overlay = ImageEnhance.Color(overlay).enhance(1.75) overlay = ImageEnhance.Brightness(overlay).enhance(1.5) color = random.choice([colours[0], colours[1]]) overlay = ImageOps.colorize(overlay, color[0], color[1]) # Overlay red and yellow onto main image and sharpen the hell out of it img = Image.blend(img, overlay, 0.75) img = ImageEnhance.Sharpness(img).enhance(150) return img
async def deepfry(img: BinaryIO) -> BinaryIO: """Deepfry logic!""" colours = ((random.randint(50, 200), random.randint(40, 170), random.randint(40, 190)), (random.randint(190, 255), random.randint(170, 240), random.randint(180, 250))) # Crush image to hell and back img = img.convert("RGB") width, height = img.width, img.height img = img.resize((int(width**random.uniform( 0.8, 0.9)), int(height**random.uniform(0.8, 0.9))), resample=PIL.Image.LANCZOS) img = img.resize((int(width**random.uniform( 0.85, 0.95)), int(height**random.uniform(0.85, 0.95))), resample=PIL.Image.BILINEAR) img = img.resize((int(width**random.uniform( 0.89, 0.98)), int(height**random.uniform(0.89, 0.98))), resample=PIL.Image.BICUBIC) img = img.resize((width, height), resample=PIL.Image.BICUBIC) img = ImageOps.posterize(img, random.randint(3, 7)) # Generate colour overlay overlay = img.split()[0] overlay = ImageEnhance.Contrast(overlay).enhance(random.uniform(1.0, 2.0)) overlay = ImageEnhance.Brightness(overlay).enhance(random.uniform( 1.0, 2.0)) overlay = ImageOps.colorize(overlay, colours[0], colours[1]) # Overlay red and yellow onto main image and sharpen the hell out of it img = PIL.Image.blend(img, overlay, random.uniform(0.1, 0.4)) img = ImageEnhance.Sharpness(img).enhance(random.randint(5, 300)) return img