Ejemplo n.º 1
0
    async def blur(self, ctx, amount: int = 25, *to_blur):

        if type(amount) is not int:
            await ctx.reply("Amount must be a number")
            return
        elif amount < -200 or amount > 200:
            await ctx.reply("Please pick a number between -200 and 200")
            return

        async with ctx.channel.typing():

            to_blur = " ".join(to_blur)
            path = "data/Temp/" + str(ctx.author.id) + "_"
            member = await self.get_member(ctx.guild, to_blur)

            try:
                await self.save_image(path + "to_blur", member,
                                      ctx.message.attachments, to_blur,
                                      ctx.author)
            except:
                success = False
            else:
                with wand_image(filename=path + "resized_to_blur") as img:
                    angle = amount * 5 / 9
                    img.rotational_blur(angle=angle)
                    img.save(filename=path + "blurred.jpg")
                success = True

        await self.clean_up(ctx, "blur", success)
Ejemplo n.º 2
0
def make_gmagik(frame, ratio1=0.5, ratio2=1.5, frames=10):
    global wand_image

    frame.transform(resize='400x400>')
    frame.background_color = Color('black')
    frame.alpha_channel = 'remove'

    orig_width = frame.width
    orig_height = frame.height

    result = wand_image()
    for i in range(frames):
        frame.liquid_rescale(
                width=int(frame.width * ratio1),
                height=int(frame.height * ratio1),
                delta_x=1, rigidity=0)

        frame.liquid_rescale(
                width=int(frame.width * ratio2),
                height=int(frame.height * ratio2),
                delta_x=2, rigidity=0)

        frame.resize(orig_width, orig_height)
        result.sequence.append(frame)
    return result
Ejemplo n.º 3
0
    async def god(self, ctx, *to_god):

        async with ctx.channel.typing():

            to_god = " ".join(to_god)
            path = "data/Temp/" + str(ctx.author.id) + "_"
            member = await self.get_member(ctx.guild, to_god)

            try:
                await self.save_image(path + "to_god", member,
                                      ctx.message.attachments, to_god,
                                      ctx.author)
            except:
                success = False
            else:
                with Image.open(path + "resized_to_god") as img:
                    img.resize((511, 255)).save(path + "resized_to_god",
                                                "JPEG")

                with wand_image(filename=path +
                                "resized_to_god") as zoomed_img:
                    zoomed_img.crop(127, 63, 383, 191)
                    zoomed_img.resize(511, 255)
                    zoomed_img.colorize(color="red",
                                        alpha="rgb(20%, 20%, 20%)")
                    zoomed_img.save(filename=path + "zoom_to_god")

                top = Image.open(path + "resized_to_god")
                bottom = Image.open(path + "zoom_to_god")
                back = Image.new("RGB", (511, 511), (0, 0, 0))

                back.paste(top, (0, 0))
                back.paste(bottom, (0, 256))
                draw = ImageDraw.Draw(back)

                x, y = 20, 20
                text = "i see no god up here"
                for i in [(1, 1), (1, -1), (-1, -1), (-1, 1)]:
                    coords = (x + i[0], y + i[1])
                    draw.text(coords, text, font=nogodfont, fill=black)
                draw.text((x, y), text, font=nogodfont, fill=white)

                x, y = 100, 460
                text = "OTHER THAN ME"
                for i in [(2, 2), (2, -2), (-2, -2), (-2, 2)]:
                    coords = (x + i[0], y + i[1])
                    draw.text(coords, text, font=godfont, fill=black)
                draw.text((x, y), text, font=godfont, fill=white)

                back.save(path + "goded.jpg")

                top.close()
                bottom.close()
                back.close()

                success = True

        await self.clean_up(ctx, "god", success)
Ejemplo n.º 4
0
    def wand(self):
        """
        Create a wand image
        """

        # If no raw data exists, fetch the url
        if len(self._raw) == 0:
            self.fetch_url()
            self._wand = wand_image(blob=self._raw[0])

        if self._wand == None:
            # Create a dummy image
            self._wand = wand_image()

            # For each frame, append it to a sequence
            for frame in self._raw:
                self._wand.sequence.append(frame)

        return self._wand
Ejemplo n.º 5
0
def generate_watermarked_pdf(input_pdf_path, watermark_name):
    text = "PDF Generated for {}".format(watermark_name)
    output_pdf = "{}.pdf".format(watermark_name)

    with wand_image(filename=input_pdf_path) as input_pdf:
        generate_watermark(input_pdf.size, text)

    stamp(
        pdf_path=input_pdf_path,
        stamp_pdf_path="watermark.pdf",
        output_pdf_path=output_pdf,
    )
    os.remove("watermark.pdf")
    print("Generated {}".format(output_pdf))
Ejemplo n.º 6
0
    def get_crt_size(self):
        """
        Returns the current size of the image as if saved on disk
        """
        # Create a temporary image
        temp_img = wand_image()
        for frame in self._raw:
            temp_img.sequence.append(frame)

        # Save it to memory
        ibytes = io.BytesIO()
        temp_img.save(file=ibytes)
        temp_img.destroy()

        return ibytes.getbuffer().nbytes
Ejemplo n.º 7
0
    def do_convert(self, compiled_file_path, image_path, working_dir):
        success = True
        error = ""
        try:
            from django.conf import settings
            resolution = int(
                getattr(settings, "L2I_IMAGEMAGICK_PNG_RESOLUTION", 96))
            with wand_image(filename=compiled_file_path,
                            resolution=resolution) as original:
                with original.convert(self.output_format) as converted:
                    converted.trim()
                    converted.save(filename=image_path)
        except Exception as e:
            success = False
            error = "%s: %s" % (type(e).__name__, str(e))

        return success, error
Ejemplo n.º 8
0
    async def av(self, ctx, *to_av):

        async with ctx.channel.typing():

            to_av = " ".join(to_av)
            path = "data/Temp/" + str(ctx.author.id) + "_"
            member = await self.get_member(ctx.guild, to_av)

            try:
                await self.save_image(path + "to_avatar", member,
                                      ctx.message.attachments, to_av,
                                      ctx.author)
            except:
                success = False
            else:
                with wand_image(filename=path + "resized_to_avatar") as img:
                    img.save(filename=path + "avatared.jpg")
                success = True

        await self.clean_up(ctx, "avatar", success)
Ejemplo n.º 9
0
    async def sneak(self, ctx, *to_sneak):

        async with ctx.channel.typing():

            to_sneak = " ".join(to_sneak)
            path = "data/Temp/" + str(ctx.author.id) + "_"
            member = await self.get_member(ctx.guild, to_sneak)

            try:
                await self.save_image(path + "to_sneak", member,
                                      ctx.message.attachments, to_sneak,
                                      ctx.author)
            except:
                success = False
            else:
                with wand_image(filename=path + "resized_to_sneak") as img:
                    img.composite(sneak_img)
                    img.save(filename=path + "sneaked.jpg")
                success = True

        await self.clean_up(ctx, "sneak", success)
Ejemplo n.º 10
0
    def proc_each_pil_frame(self, func, send_file, send_msg, args={}):
        new_img = Image()
        self.print_memusage("Before start")
        try:
            send_msg("Working...")
            img = self.pil()

            modified_frames = False
            for idx, frame in enumerate(pil_imagesequence.Iterator(img)):
                # For each frame, call the image processor
                result = func(frame.convert("RGBA"), **args)
                if result != None:
                    modified_frames = True
                else:
                    result = frame

                # Append it to the results
                ibytes = io.BytesIO()
                result.save(ibytes, "PNG")

                ibytes.seek(0)
                new_img.append(wand_image(file=ibytes))

                # Check if we're not consuming too much memory
                new_img.check_size(idx + 1)

            if modified_frames:
                new_img.send_img_reply(send_file)
            else:
                send_msg("No frames changed. Not returning anything")
        except:
            import traceback

            traceback.print_exc()
            send_msg("Something didn't work.")
        finally:
            new_img.clean_data()

        self.clean_data()
        self.print_memusage("After finish")
Ejemplo n.º 11
0
    async def bigpp(self, ctx, *to_bigpp):

        async with ctx.channel.typing():

            to_bigpp = " ".join(to_bigpp)
            path = "data/Temp/" + str(ctx.author.id) + "_"
            member = await self.get_member(ctx.guild, to_bigpp)

            try:
                await self.save_image(path + "to_bigpp", member,
                                      ctx.message.attachments, to_bigpp,
                                      ctx.author)
            except:
                success = False
            else:
                with wand_image(filename=path + "resized_to_bigpp") as img:
                    img.implode(amount=-7)
                    img.composite(bigpp_img)
                    img.save(filename=path + "bigpped.jpg")
                success = True

        await self.clean_up(ctx, "bigpp", success)
Ejemplo n.º 12
0
    async def trigger(self, ctx, *to_trigger):

        async with ctx.channel.typing():

            to_trigger = " ".join(to_trigger)
            path = "data/Temp/" + str(ctx.author.id) + "_"
            member = await self.get_member(ctx.guild, to_trigger)

            try:
                await self.save_image(path + "to_trigger", member,
                                      ctx.message.attachments, to_trigger,
                                      ctx.author)
            except:
                success = False
            else:
                with wand_image(filename=path + "resized_to_trigger") as img:
                    img.rotational_blur(angle=30)
                    img.composite(triggered_img)
                    img.rotational_blur(angle=10)
                    img.save(filename=path + "triggered.jpg")
                success = True

        await self.clean_up(ctx, "trigger", success)
Ejemplo n.º 13
0
from PIL import Image, ImageDraw, ImageFont
from discord.ext import commands
from discord import File
import requests
import re

black = (0, 0, 0)
white = (255, 255, 255)
try:  # Windows
    nogodfont = ImageFont.truetype("arial.ttf", 30)
    godfont = ImageFont.truetype("arial.ttf", 50)
except:  # Linux
    nogodfont = ImageFont.truetype("/usr/src/app/data/arial.ttf", 30)
    godfont = ImageFont.truetype("/usr/src/app/data/arial.ttf", 50)

bigpp_img = wand_image(filename="data/imgs/bigpp.png")
smolpp_img = wand_image(filename="data/imgs/smolpp.png")
bonk_img = wand_image(filename="data/imgs/bonk.png")
triggered_img = wand_image(filename="data/imgs/triggered.png")
sneak_img = wand_image(filename="data/imgs/sneak.png")
url = "https://cdn.filestackcontent.com/AWM47Q1KrQqWAvDUZduCYz/resize=width:512,height:512,fit:scale/"
is_img_url = re.compile(
    "(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*\.(?:jpg|gif|png))(?:\?([^#]*))?(?:#(.*))?"
)


class ImageCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
Ejemplo n.º 14
0
def generate_watermark(doc_size, text):
    img = Image.new("RGBA", doc_size, color=(255, 255, 255, 0))
    draw = ImageDraw.Draw(img)

    line_break = 15
    multiline_text = textwrap.wrap(text, width=15)
    fill_color = (255, 255, 255)
    shadow_color = (0, 0, 0)

    fontsize = 12
    font = ImageFont.truetype("arial.ttf", fontsize)

    # Initial position of text
    x = doc_size[0] - (line_break) * fontsize * 0.6
    y = doc_size[1] - (fontsize + 2) * len(multiline_text)

    line_position = 0
    for line in multiline_text:
        # thin border
        draw.text((x - 1, y + line_position),
                  line,
                  font=font,
                  fill=shadow_color)
        draw.text((x + 1, y + line_position),
                  line,
                  font=font,
                  fill=shadow_color)
        draw.text((x, y - 1 + line_position),
                  line,
                  font=font,
                  fill=shadow_color)
        draw.text((x, y + 1 + line_position),
                  line,
                  font=font,
                  fill=shadow_color)

        # thicker border
        draw.text((x - 1, y - 1 + line_position),
                  line,
                  font=font,
                  fill=shadow_color)
        draw.text((x + 1, y - 1 + line_position),
                  line,
                  font=font,
                  fill=shadow_color)
        draw.text((x - 1, y + 1 + line_position),
                  line,
                  font=font,
                  fill=shadow_color)
        draw.text((x + 1, y + 1 + line_position),
                  line,
                  font=font,
                  fill=shadow_color)

        # now draw the text over it
        draw.text((x, y + line_position), line, font=font, fill=fill_color)

        line_position += fontsize + 2

    img.save("watermark.png")

    with wand_image(filename="watermark.png") as watermark_img:
        watermark_img.format = "pdf"
        watermark_img.save(filename="watermark.pdf")
    os.remove("watermark.png")
Ejemplo n.º 15
0
    for line in lines:
        width, height = font.getsize(line)
        text_w, text_h = draw.textsize(line, font)
        draw.text(((w - text_w - int(ratio_w * 140)), y_text),
                  line, (0, 0, 0),
                  font=font)
        y_text += height_fixed * 1.2

    return frame


if (len(filename.split('.gif')) > 1):
    # im is your original image

    frame_info = []
    src_image = wand_image(filename=filename)
    i = 0
    for frame in src_image.sequence:
        with wand_image() as dst_image:
            print(frame.container)
            dst_image.sequence.append(frame)
            print(frame.delay)
            frame_info.append({
                'left': frame.page_x,
                'top': frame.page_y,
                'height': frame.height,
                'width': frame.width
            })
            dst_image.save(filename="temp/ol%d.png" % i)
            print(dst_image.height)
            i += 1