async def do_img_manip(ctx, image, *, method: str, filename: str, method_args: list = None, method_kwargs: dict = None): async with ctx.typing(): with ctx.bot.utils.StopWatch() as sw: # get the image if ctx.message.attachments: img = polaroid.Image(await ctx.message.attachments[0].read()) elif isinstance(image, discord.PartialEmoji): img = polaroid.Image(await image.url.read()) else: img = image or ctx.author img = polaroid.Image(await img.avatar_url_as(format="png" ).read()) # manipulate the image if method_args is None: method_args = [] if method_kwargs is None: method_kwargs = {} method = getattr(img, method) method(*method_args, **method_kwargs) # build and send the embed file = discord.File(BytesIO(img.save_bytes()), filename=f"{filename}.png") embed = discord.Embed(colour=ctx.bot.embed_colour) embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_image(url=f"attachment://{filename}.png") embed.set_footer(text=f"Finished in {sw.elapsed:.3f} seconds") await ctx.send(embed=embed, file=file)
async def manip(self, ctx, image, *, method: str, method_args: list = None, text: str = None): async with ctx.typing(): # get the image if ctx.message.attachments: img = polaroid.Image(await ctx.message.attachments[0].read()) elif isinstance(image, discord.PartialEmoji): img = polaroid.Image(await image.url.read()) else: img = image or ctx.author img = polaroid.Image(await img.avatar_url_as(format="png").read()) # manipulate the image img.resize(500, 500, 1) if method_args is None: method_args = [] method = getattr(img, method) method(*method_args) file = discord.File(BytesIO(img.save_bytes()), filename="polaroid.png") embed = discord.Embed(description=text, colour=self.bot.embed_color, timestamp=ctx.message.created_at) embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_image(url="attachment://polaroid.png") embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed, file=file)
async def get_image(ctx, image): if ctx.message.attachments: return polaroid.Image(await ctx.message.attachments[0].read()) elif isinstance(image, discord.PartialEmoji): return polaroid.Image(await image.url.read()) else: image = image or ctx.author return polaroid.Image(await image.avatar_url_as(format="png").read())
def generate_image(image: bytes, radius: int, intensity: float) -> BytesIO: """The backend code that generates the oil'd effect for the image.""" image = polaroid.Image(image) image.oil(radius, intensity) buffer = BytesIO(image.save_bytes()) return buffer
def generate_image(first_image: bytes, second_image: bytes) -> BytesIO: """Backend code that generates the image that provides the facetime effect.""" img_one = polaroid.Image(first_image) img_two = polaroid.Image(second_image) img_one.resize(1024, 1024, 5) img_two.resize(256, 256, 5) facetime_btns = polaroid.Image("./static/facetimebuttons.png") facetime_btns.resize(1024, 1024, 5) img_one.watermark(img_two, 15, 15) img_one.watermark(facetime_btns, 0, 390) buffer = BytesIO(img_one.save_bytes()) return buffer
def generate_image(image: bytes) -> BytesIO: """The backend code that generates the inverted effect for the image.""" image = polaroid.Image(image) image.invert() buffer = BytesIO(image.save_bytes()) return buffer
def do_polaroid(self, img, method: str, args: list = None, kwargs: dict = None): img = polaroid.Image(img) if args is None: args = [] if kwargs is None: kwargs = {} method = getattr(img, method) method(*args, **kwargs) return img
def do_magic(): i = WandImage(blob=avimg) i.format = 'jpg' #thanks daggy https://github.com/daggy1234/dagpi-image i.virtual_pixel = "mirror" i.resize(250, 250) x, y = i.width, i.height arguments = (0, 0, 77, 153, x, 0, 179, 153, 0, y, 51, 255, x, y, 204, 255) i.distort("perspective", arguments) byt = i.make_blob() im = polaroid.Image(byt) im.resize(500, 500, 1) file = discord.File(BytesIO(im.save_bytes()), filename="magik.jpg") return file
def do_magic(): i = WandImage(blob=avimg) i.format = 'jpg' i.liquid_rescale(width=int(i.width * 0.5), height=int(i.height * 0.5), delta_x=int(0.5 * scale) if scale else 1, rigidity=0) i.liquid_rescale(width=int(i.width * 1.5), height=int(i.height * 1.5), delta_x=scale if scale else 2, rigidity=0) byt = i.make_blob() im = polaroid.Image(byt) im.resize(500, 500, 1) file = discord.File(BytesIO(im.save_bytes()), filename="magik.jpg") return file
def do_polaroid(image, method: str, args: list = [], kwargs: dict = {}): img = polaroid.Image(image) method = getattr(img, method) method(*args, **kwargs) bytes_ = img.save_bytes() return bytes_
def liquid_rescale(self, ctx, image): img = polaroid.Image(image) img.liquid_rescale(int(int(img.width) / 2), int(int(img.height) / 2)) return img
def sync_func(): im = polaroid.Image(byt) im.resize(width, height, 1) file = discord.File(BytesIO(im.save_bytes()), filename="stretched.png") return file