Example #1
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(
            self.assets.get('assets/changemymind/changemymind.bmp')).convert(
                'RGBA')
        # We need a text layer here for the rotation
        text_layer = Image.new('RGBA', base.size)
        font, text = auto_text_size(
            text, self.assets.get_font('assets/fonts/sans.ttf'), 310)
        canv = ImageDraw.Draw(text_layer)

        render_text_with_emoji(text_layer,
                               canv, (290, 300),
                               text,
                               font=font,
                               fill='Black')

        text_layer = text_layer.rotate(23, resample=Image.BICUBIC)

        base.paste(text_layer, (0, 0), text_layer)
        base = base.convert('RGB')

        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #2
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open("assets/obama/obama.jpg")
        font = ImageFont.truetype("assets/fonts/arimobold.ttf", size=36)
        canv = ImageDraw.Draw(base)

        avatar = (http.get_image(avatars[0]).resize(
            (200, 200), Image.LANCZOS).convert("RGBA"))

        w, _ = canv.textsize(wrap(font, usernames[0], 400), font)

        base.paste(avatar, (120, 73), avatar)
        base.paste(avatar, (365, 0), avatar)

        render_text_with_emoji(
            base,
            canv,
            (int(210 - (w / 2)), 400),
            wrap(font, usernames[0], 400),
            font,
            "white",
        )
        render_text_with_emoji(
            base,
            canv,
            (int(470 - (w / 2)), 300),
            wrap(font, usernames[0], 400),
            font,
            "white",
        )

        base = base.convert("RGB")
        b = BytesIO()
        base.save(b, format="jpeg")
        b.seek(0)
        return send_file(b, mimetype="image/jpeg")
Example #3
0
 def draw_text_with_outline(string, x, y):
     x = int(x)
     y = int(y)
     render_text_with_emoji(img,
                            draw, (x - 2, y - 2),
                            string,
                            font=font,
                            fill=(0, 0, 0))
     render_text_with_emoji(img,
                            draw, (x + 2, y - 2),
                            string,
                            font=font,
                            fill=(0, 0, 0))
     render_text_with_emoji(img,
                            draw, (x + 2, y + 2),
                            string,
                            font=font,
                            fill=(0, 0, 0))
     render_text_with_emoji(img,
                            draw, (x - 2, y + 2),
                            string,
                            font=font,
                            fill=(0, 0, 0))
     render_text_with_emoji(img,
                            draw, (x, y),
                            string,
                            font=font,
                            fill=color)
Example #4
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open('assets/confusedcat/confusedcat.bmp')
        font = ImageFont.truetype('assets/fonts/medium.woff', size=36)
        canv = ImageDraw.Draw(base)
        try:
            ladies, cat = text.replace(' ,', ',', 1).split(',', 1)
        except ValueError:
            ladies = 'Dank Memer'
            cat = 'People who forget to split text with a comma'
        ladies = wrap(font, ladies, 510)
        cat = wrap(font, cat, 510)
        render_text_with_emoji(base,
                               canv, (5, 5),
                               ladies[:100],
                               font=font,
                               fill='Black')
        render_text_with_emoji(base,
                               canv, (516, 5),
                               cat[:100],
                               font=font,
                               fill='Black')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #5
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(
            self.assets.get('assets/surprised/surprised.bmp')).convert('RGBA')
        font = self.assets.get_font('assets/fonts/robotoregular.ttf', size=36)
        try:
            text1, text2 = text.replace(', ', ',').split(',')
        except ValueError:
            text1, text2 = 'tries to use surprised without splitting by comma,the command breaks'.split(
                ',')
        text1 = wrap(font, 'me: ' + text1, 650)
        text2 = wrap(font, 'also me: ' + text2, 650)
        canv = ImageDraw.Draw(base)
        render_text_with_emoji(base,
                               canv, (20, 20),
                               text1,
                               font=font,
                               fill='White')
        render_text_with_emoji(base,
                               canv, (20, 140),
                               text2,
                               font=font,
                               fill='White')
        base = base.convert('RGB')

        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #6
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(
            self.assets.get('assets/violentsparks/violentsparks.bmp'))
        font = self.assets.get_font('assets/fonts/medium.woff', size=36)
        canv = ImageDraw.Draw(base)
        try:
            me, sparks = text.replace(' ,', ',', 1).split(',', 1)
        except ValueError:
            sparks = 'me'
            me = 'Dank Memer being mad that I forgot to split my text with a comma'
        me = wrap(font, me, 550)
        sparks = wrap(font, sparks, 400)
        render_text_with_emoji(base,
                               canv, (15, 5),
                               me,
                               font=font,
                               fill='White')
        render_text_with_emoji(base,
                               canv, (15, 567),
                               sparks,
                               font=font,
                               fill='White')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #7
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/byemom/mom.bmp'))
        avatar = http.get_image(avatars[0]).convert('RGBA').resize((70, 70), resample=Image.BICUBIC)
        avatar2 = avatar.copy().resize((125, 125), resample=Image.BICUBIC)
        text_layer = Image.new('RGBA', (350, 25))
        bye_layer = Image.new('RGBA', (180, 51), (255, 255, 255))
        font = self.assets.get_font('assets/fonts/arial.ttf', size=20)
        bye_font = self.assets.get_font('assets/fonts/arimobold.ttf', size=14)
        canv = ImageDraw.Draw(text_layer)
        bye = ImageDraw.Draw(bye_layer)
        username = usernames[0] or 'Tommy'
        msg = 'Alright {} im leaving the house to run some errands'.format(username)

        text = wrap(font, text, 500)
        msg = wrap(font, msg, 200)

        render_text_with_emoji(text_layer, canv, (0, 0), text, font=font, fill='Black')
        render_text_with_emoji(bye_layer, bye, (0, 0), msg, font=bye_font, fill=(42, 40, 165))
        text_layer = text_layer.rotate(24.75, resample=Image.BICUBIC, expand=True)

        base.paste(text_layer, (350, 443), text_layer)
        base.paste(bye_layer, (150, 7))
        base.paste(avatar, (530, 15), avatar)
        base.paste(avatar2, (70, 340), avatar2)
        base = base.convert('RGBA')

        b = BytesIO()
        base.save(b, format='png')
        b.seek(0)
        return send_file(b, mimetype='image/png')
Example #8
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open('assets/doglemon/doglemon.bmp')
        font = ImageFont.truetype('assets/fonts/medium.woff', size=30)
        canv = ImageDraw.Draw(base)
        try:
            lemon, dog = text.replace(' ,', ',', 1).split(',', 1)
        except ValueError:
            lemon = 'Text that is not seperated by comma'
            dog = 'Dank Memer'
        lemon = wrap(font, lemon, 450)
        dog = wrap(font, dog, 450)
        render_text_with_emoji(base,
                               canv, (850, 100),
                               lemon[:180],
                               font=font,
                               fill='Black')
        render_text_with_emoji(base,
                               canv, (500, 100),
                               dog[:200],
                               font=font,
                               fill='White')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #9
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/cheating/cheating.bmp'))
        font = self.assets.get_font('assets/fonts/medium.woff', size=26)
        canv = ImageDraw.Draw(base)
        try:
            me, classmate = text.replace(' ,', ',', 1).split(',', 1)
        except ValueError:
            me = 'aight thx'
            classmate = 'yo dude, you need to split the text with a comma'
        me = wrap(font, me, 150)
        classmate = wrap(font, classmate, 150)
        render_text_with_emoji(base,
                               canv, (15, 300),
                               me[:50],
                               font=font,
                               fill='White')
        render_text_with_emoji(base,
                               canv, (155, 200),
                               classmate[:50],
                               font=font,
                               fill='White')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #10
0
    def generate(self, avatars, text, usernames, kwargs):

        base = Image.open(
            self.assets.get('assets/garfield/garfield.png')).convert('RGB')
        no_entry = Image.open(self.assets.get(
            'assets/garfield/no_entry.png')).convert('RGBA').resize(
                (224, 224), Image.LANCZOS)
        font = self.assets.get_font('assets/fonts/arial.ttf', size=28)
        avatar = get_image(avatars[0]).resize((192, 192),
                                              Image.LANCZOS).convert('RGBA')
        avatar2 = avatar.copy().resize((212, 212),
                                       Image.LANCZOS).convert('RGBA')

        base.paste(avatar, (296, 219), avatar)
        base.paste(no_entry, (280, 203), no_entry)
        base.paste(avatar2, (40, 210), avatar2)

        draw = ImageDraw.Draw(base)
        render_text_with_emoji(base, draw, (15, 0),
                               wrap(font, text, base.width), font, 'black')

        b = BytesIO()
        base.save(b, format='png')
        b.seek(0)
        return send_file(b, mimetype='image/png')
Example #11
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/sneakyfox/sneakyfox.bmp'))
        font = self.assets.get_font('assets/fonts/arimobold.ttf', size=36)
        canv = ImageDraw.Draw(base)
        try:
            fox, otherthing = text.replace(' ,', ',', 1).split(',', 1)
        except ValueError:
            fox = 'Text that is not split with a comma'
            otherthing = 'the bot'
        fox = wrap(font, fox, 500)
        otherthing = wrap(font, otherthing, 450)
        render_text_with_emoji(base,
                               canv, (50, 385),
                               fox[:180],
                               font=font,
                               fill='Black')
        render_text_with_emoji(base,
                               canv, (670, 150),
                               otherthing[:180],
                               font=font,
                               fill='Black')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #12
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open("assets/violentsparks/violentsparks.bmp")
        font = ImageFont.truetype("assets/fonts/medium.woff", size=36)
        canv = ImageDraw.Draw(base)
        try:
            me, sparks = text.replace(" ,", ",", 1).split(",", 1)
        except ValueError:
            sparks = "me"
            me = "Dank Memer being mad that I forgot to split my text with a comma"
        me = wrap(font, me, 550)
        sparks = wrap(font, sparks, 200)
        render_text_with_emoji(base,
                               canv, (15, 5),
                               me,
                               font=font,
                               fill="White")
        render_text_with_emoji(base,
                               canv, (350, 430),
                               sparks,
                               font=font,
                               fill="Black")

        base = base.convert("RGB")
        b = BytesIO()
        base.save(b, format="jpeg")
        b.seek(0)
        return send_file(b, mimetype="image/jpeg")
Example #13
0
async def confusedcat(request):
    base = Image.open("assets/confusedcat/confusedcat.bmp")
    font = ImageFont.truetype("assets/fonts/medium.woff", size=36)
    text = request.headers.get("text")
    canv = ImageDraw.Draw(base)
    try:
        ladies, cat = text.replace(" ,", ",", 1).split(",", 1)
    except ValueError:
        ladies = "Dank Memer"
        cat = "People who forget to split text with a comma"
    ladies = wrap(font, ladies, 510)
    cat = wrap(font, cat, 510)
    render_text_with_emoji(base,
                           canv, (5, 5),
                           ladies[:100],
                           font=font,
                           fill="Black")
    render_text_with_emoji(base,
                           canv, (516, 5),
                           cat[:100],
                           font=font,
                           fill="Black")

    base = base.convert("RGB")
    return gen_file_response(base, {"format": "png"})
Example #14
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open("assets/surprised/surprised.bmp").convert("RGBA")
        font = ImageFont.truetype("assets/fonts/robotoregular.ttf", size=36)
        try:
            text1, text2 = text.replace(", ", ",").split(",")
        except ValueError:
            (
                text1,
                text2,
            ) = "tries to use surprised without splitting by comma,the command breaks".split(
                ",")
        text1 = wrap(font, "me: " + text1, 650)
        text2 = wrap(font, "also me: " + text2, 650)
        canv = ImageDraw.Draw(base)
        render_text_with_emoji(base,
                               canv, (20, 20),
                               text1,
                               font=font,
                               fill="White")
        render_text_with_emoji(base,
                               canv, (20, 140),
                               text2,
                               font=font,
                               fill="White")
        base = base.convert("RGB")

        b = BytesIO()
        base.save(b, format="jpeg")
        b.seek(0)
        return send_file(b, mimetype="image/jpeg")
Example #15
0
async def cheating(request):
    base = Image.open("assets/cheating/cheating.bmp")
    font = ImageFont.truetype("assets/fonts/medium.woff", size=26)
    text = request.headers.get("text")
    canv = ImageDraw.Draw(base)
    try:
        me, classmate = text.replace(" ,", ",", 1).split(",", 1)
    except ValueError:
        me = "aight thx"
        classmate = "yo dude, you need to split the text with a comma"
    me = wrap(font, me, 150)
    classmate = wrap(font, classmate, 150)
    render_text_with_emoji(base,
                           canv, (15, 300),
                           me[:50],
                           font=font,
                           fill="White")
    render_text_with_emoji(base,
                           canv, (155, 200),
                           classmate[:50],
                           font=font,
                           fill="White")

    base = base.convert("RGB")
    return gen_file_response(base, {"format": "png"})
Example #16
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open("assets/knowyourlocation/knowyourlocation.bmp").convert(
            "RGBA"
        )
        # We need a text layer here for the rotation
        canv = ImageDraw.Draw(base)

        text = text.split(", ")

        if len(text) != 2:
            text = ["Separate the items with a", "comma followed by a space"]

        top, bottom = text

        top_font, top_text = auto_text_size(
            top, ImageFont.truetype("assets/fonts/sans.ttf"), 630
        )
        bottom_font, bottom_text = auto_text_size(
            bottom, ImageFont.truetype("assets/fonts/sans.ttf"), 539
        )
        render_text_with_emoji(base, canv, (64, 131), top_text, top_font, "black")
        render_text_with_emoji(
            base, canv, (120, 450), bottom_text, bottom_font, "black"
        )
        base = base.convert("RGB")

        b = BytesIO()
        base.save(b, format="jpeg")
        b.seek(0)
        return send_file(b, mimetype="image/jpeg")
Example #17
0
async def cry(request):
    base = Image.open("assets/cry/cry.bmp")
    font = ImageFont.truetype("assets/fonts/tahoma.ttf", size=20)
    canv = ImageDraw.Draw(base)
    text = request.headers.get("text")
    text = wrap(font, text, 180)
    render_text_with_emoji(base, canv, (382, 80), text, font=font, fill="Black")
    return gen_file_response(base, {"format": "png"})
Example #18
0
async def abandon(request):
    args = await getarg(request)
    text = args[2][0]
    base = Image.open("assets/abandon/abandon.bmp")
    font = ImageFont.truetype("assets/fonts/verdana.ttf", 24)
    canv = ImageDraw.Draw(base)
    render_text_with_emoji(base, canv, (25, 413), wrap(font, text, 320), font,
                           "black")
    base = base.convert("RGB")
    return gen_file_response(base, {"format": "png"})
Example #19
0
async def excuseme(request):
    base = Image.open("assets/excuseme/excuseme.bmp")

    font = ImageFont.truetype("assets/fonts/sans.ttf", size=40)
    canv = ImageDraw.Draw(base)
    text = request.headers.get("text")
    text = wrap(font, text, 787)
    render_text_with_emoji(base, canv, (20, 15), text, font=font, fill="Black")

    base = base.convert("RGB")
    return gen_file_response(base, {"format": "png"})
Example #20
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/abandon/abandon.bmp'))
        font = self.assets.get_font('assets/fonts/verdana.ttf', size=24)
        canv = ImageDraw.Draw(base)
        render_text_with_emoji(base, canv, (25, 413), wrap(font, text, 320), font, 'black')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #21
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/violence/violence.jpg'))
        font = self.assets.get_font('assets/fonts/arimobold.ttf', size=24)
        canv = ImageDraw.Draw(base)
        render_text_with_emoji(base, canv, (355, 0), wrap(font, text, 270), font, 'black')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #22
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/cry/cry.bmp'))
        font = self.assets.get_font('assets/fonts/tahoma.ttf', size=20)
        canv = ImageDraw.Draw(base)

        text = wrap(font, text, 180)
        render_text_with_emoji(base, canv, (382, 80), text, font=font, fill='Black')

        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #23
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open('assets/presentation/presentation.bmp')
        font = ImageFont.truetype('assets/fonts/verdana.ttf', size=24)
        canv = ImageDraw.Draw(base)
        text = wrap(font, text, 330)
        render_text_with_emoji(base, canv, (150, 80), text, font=font, fill='Black')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #24
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open("assets/violence/violence.jpg")
        font = ImageFont.truetype("assets/fonts/arimobold.ttf", size=24)
        canv = ImageDraw.Draw(base)
        render_text_with_emoji(base, canv, (355, 0), wrap(font, text, 270),
                               font, "black")

        base = base.convert("RGB")
        b = BytesIO()
        base.save(b, format="jpeg")
        b.seek(0)
        return send_file(b, mimetype="image/jpeg")
Example #25
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open('assets/ohno/ohno.bmp').convert('RGBA')
        font = ImageFont.truetype('assets/fonts/sans.ttf', size=16 if len(text) > 38 else 32)
        canv = ImageDraw.Draw(base)

        text = wrap(font, text, 260)
        render_text_with_emoji(base, canv, (340, 30), text, font=font, fill='Black')
        base = base.convert('RGB')

        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #26
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/humansgood/humansgood.bmp')).convert('RGBA')
        # We need a text layer here for the rotation
        font, text = auto_text_size(text, self.assets.get_font('assets/fonts/sans.ttf'),
                                    125, font_scalar=0.7)
        canv = ImageDraw.Draw(base)
        render_text_with_emoji(base, canv, (525, 762), text, font, 'black')
        base = base.convert('RGB')

        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #27
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/excuseme/excuseme.bmp'))

        font = self.assets.get_font('assets/fonts/sans.ttf', size=40)
        canv = ImageDraw.Draw(base)
        text = wrap(font, text, 787)
        render_text_with_emoji(base, canv, (20, 15), text, font=font, fill='Black')

        base = base.convert('RGB')

        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #28
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open('assets/emergencymeeting/emergencymeeting.bmp')
        font = ImageFont.truetype('assets/fonts/medium.woff', size=33)
        canv = ImageDraw.Draw(base)
        if len(text) >= 140:
            text = text[:137] + "..."
        text = wrap(font, text, 750)
        render_text_with_emoji(base, canv, (0, 0), text, font=font, fill='Black')

        base = base.convert('RGB')
        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #29
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open(self.assets.get('assets/balloon/balloon.bmp')).convert('RGBA')
        font = self.assets.get_font('assets/fonts/sans.ttf')
        canv = ImageDraw.Draw(base)

        text = text.split(', ')

        if len(text) != 2:
            text = ["Separate the items with a", "comma followed by a space"]

        balloon, label = text

        balloon_text_1_font, balloon_text_1 = auto_text_size(balloon, font, 162)
        balloon_text_2_font, balloon_text_2 = auto_text_size(balloon, font, 170, font_scalar=0.95)
        balloon_text_3_font, balloon_text_3 = auto_text_size(balloon, font, 110, font_scalar=0.8)
        label_font, label_text = auto_text_size(label, font, 125)

        render_text_with_emoji(base, canv, (80, 180), balloon_text_1, font=balloon_text_1_font, fill='Black')
        render_text_with_emoji(base, canv, (50, 530), balloon_text_2, font=balloon_text_2_font, fill='Black')
        render_text_with_emoji(base, canv, (500, 520), balloon_text_3, font=balloon_text_3_font, fill='Black')
        render_text_with_emoji(base, canv, (620, 155), label_text, font=label_font, fill='Black')
        base = base.convert('RGB')

        b = BytesIO()
        base.save(b, format='jpeg')
        b.seek(0)
        return send_file(b, mimetype='image/jpeg')
Example #30
0
    def generate(self, avatars, text, usernames, kwargs):
        base = Image.open("assets/walking/walking.bmp")

        font = ImageFont.truetype("assets/fonts/sans.ttf", size=50)
        canv = ImageDraw.Draw(base)
        text = wrap(font, text, 1000)
        render_text_with_emoji(base, canv, (35, 35), text, font=font, fill="black")

        base = base.convert("RGB")

        b = BytesIO()
        base.save(b, format="jpeg")
        b.seek(0)
        return send_file(b, mimetype="image/jpeg")