Ejemplo n.º 1
0
def generate_meme(upper_text, lower_text, picture_name_orig,
                  picture_name_target):
    main_image = Image(filename=join(TEMPLATES_FOLDER, picture_name_orig))
    main_image.resize(
        1024,
        int(((main_image.height * 1.0) / (main_image.width * 1.0)) * 1024.0))

    upper_text = "\n".join(wrap(upper_text,
                                get_warp_length(main_image.width))).upper()
    lower_text = "\n".join(wrap(lower_text,
                                get_warp_length(main_image.width))).upper()
    lower_margin = MARGINS[lower_text.count("\n")]

    text_draw = Drawing()

    text_draw.font = join(getcwd(), "impact.ttf")
    text_draw.font_size = 70
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")

    if upper_text:
        text_draw.text(int(main_image.width / 2), 80, upper_text)
    if lower_text:
        text_draw.text(int(main_image.width / 2),
                       main_image.height - lower_margin, lower_text)

    text_draw(main_image)

    main_image.save(filename=join(getcwd(), MEME_FOLDER, picture_name_target))
Ejemplo n.º 2
0
async def remix_meeme(upper_text, lower_text, picture_name, endname):
    main_image = remiximage(filename=picture_name)
    main_image.resize(
        1024,
        int(((main_image.height * 1.0) / (main_image.width * 1.0)) * 1024.0))
    upper_text = "\n".join(wrap(upper_text,
                                get_warp_length(main_image.width))).upper()
    lower_text = "\n".join(wrap(lower_text,
                                get_warp_length(main_image.width))).upper()
    lower_margin = MARGINS[lower_text.count("\n")]
    text_draw = Drawing()
    text_draw.font = join(getcwd(),
                          "userbot/utils/styles/MutantAcademyStyle.ttf")
    text_draw.font_size = 100
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")
    if upper_text:
        text_draw.text((main_image.width) // 2, 80, upper_text)
    if lower_text:
        text_draw.text((main_image.width) // 2,
                       main_image.height - lower_margin, lower_text)
    text_draw(main_image)
    main_image.save(filename=endname)
 def draw_text(self,
               image,
               x,
               y,
               text,
               font_size=15,
               font_style='normal',
               font=None,
               text_alignment='left',
               text_color='Black',
               filename=None,
               is_display=False):
     draw = Drawing()
     print('draw text={} in x={}, y={}'.format(text, x, y))
     if font is not None:
         draw.font = font
     draw.fill_color = Color(text_color)
     draw.font_size = font_size
     draw.font_style = font_style
     draw.text_alignment = text_alignment
     draw.text(x, y, text)
     draw(image)
     if is_display:
         display(image)
     if filename is not None:
         image.save(filename=filename)
     return image
Ejemplo n.º 4
0
 def text_wrap(self,image):
     draw = Drawing()
     draw.font = 'wandtests/assets/League_Gothic.otf'
     draw.fill_color = Color(self.__getitem__('color'))
     draw.text_alignment = 'center'
     image.font_size = self.__getitem__('font_size')
     draw.text(int(self.__getitem__('width_place')*image.width), int(self.__getitem__('height_place')*image.height), self.__getitem__('quote'))
     draw(image)
     return image
Ejemplo n.º 5
0
def generate_meme(upper_text, lower_text, picture_name):
    MEME_FOLDER = "memes"
    MARGINS = [25, 65, 100, 135, 170]

    if not exists(join(getcwd(), MEME_FOLDER)):
        mkdir(join(getcwd(), MEME_FOLDER))

    main_image = Image(filename=picture_name)
    main_image.resize(
        500, int(
            ((main_image.height * 1.0) / (main_image.width * 1.0)) * 500.0))

    upper_text = "\n".join(wrap(upper_text,
                                get_warp_length(main_image.width))).upper()
    lower_text = "\n".join(wrap(lower_text,
                                get_warp_length(main_image.width))).upper()
    lower_margin = MARGINS[lower_text.count("\n")]

    text_draw = Drawing()

    text_draw.font = join(getcwd(), "impact.ttf")
    text_draw.font_size = 40
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")

    if upper_text:
        text_draw.text(main_image.width / 2, 40, upper_text)
    if lower_text:
        text_draw.text(main_image.width / 2, main_image.height - lower_margin,
                       lower_text)

    text_draw(main_image)

    outname = "[MEME] " + picture_name
    main_image.save(filename=join(getcwd(), MEME_FOLDER, outname))

    # if sys.platform.startswith('darwin'):
    #     system('open "%s"' % (join(getcwd(), MEME_FOLDER, outname)))
    # elif name == 'nt':
    #     system('start "%s"' % (join(getcwd(), MEME_FOLDER, outname)))
    # elif name == 'posix':
    #     system('xdg-open "%s"' % (join(getcwd(), MEME_FOLDER, outname)))
    # else:
    #     pass
    return MEME_FOLDER + '/' + outname
Ejemplo n.º 6
0
 async def create_text_image(self, ctx: Context, person: str, text: str):
     """
     Creates an image of a given person with the specified text.
     """
     lines = textwrap.wrap(text, 15)
     draw = Drawing()
     image = Image(filename=f"bot/resources/{person}SaysBlank.png")
     draw.font = "bot/resources/Dosis-SemiBold.ttf"
     draw.text_alignment = "center"
     draw.font_size = 34
     offset = 45 - 10 * len(lines)
     for line in lines:
         draw.text(image.width // 5 + 20, image.height // 5 + offset, line)
         offset += 35
     draw(image)
     image.save(filename=f"bot/resources/{person}Says.png")
     await ctx.send(file=File(f"bot/resources/{person}Says.png"))
Ejemplo n.º 7
0
    def make_og_meme(self, top, bottom):
        """Generate an OG Meme
        """

        wand_t = Image(blob=self.image.read())
        MARGINS = [50, 130, 200, 270, 340]

        # Set a minimum size
        wand_t.resize(
            1024, int(((wand_t.height * 1.0) / (wand_t.width * 1.0)) * 1024.0))

        use_top = True
        use_bottom = True

        if top == ' ':
            use_top = False
        if bottom == ' ':
            use_bottom = False

        if use_top:
            upper_text = "\n".join(
                wrap(top, self.get_warp_length(int(wand_t.width)))).upper()
        if use_bottom:
            lower_text = "\n".join(
                wrap(bottom, self.get_warp_length(int(wand_t.width)))).upper()
            lower_margin = MARGINS[lower_text.count("\n")]

        text_draw = Drawing()

        text_draw.font = "fonts/Anton-Regular.ttf"
        text_draw.font_size = 70
        text_draw.text_alignment = "center"
        text_draw.stroke_color = Color("black")
        text_draw.stroke_width = 3
        text_draw.fill_color = Color("white")

        if use_top:
            text_draw.text(int(wand_t.width / 2), 80, upper_text)

        if use_bottom:
            text_draw.text(int(wand_t.width / 2),
                           int(wand_t.height - lower_margin), lower_text)

        text_draw(wand_t)

        return (wand_t)
Ejemplo n.º 8
0
def generar_meme(texto, nombre_imagen):
    imagen = Image(filename=nombre_imagen)
    imagen.resize(1024,
                  int(((imagen.height * 1.0) / (imagen.width * 1.0)) * 1024.0))

    texto = "\n".join(wrap(texto, get_length(imagen.width))).upper()

    text_draw = Drawing()

    text_draw.font = os.path.join(os.getcwd(), "impact.ttf")
    text_draw.font_size = 60
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")

    if texto:
        text_draw.text(imagen.width * 60//100, imagen.height * 55//100, texto)

    text_draw(imagen)

    imagen.save(filename=os.path.join(os.getcwd(), "memes", "meme.jpg"))
Ejemplo n.º 9
0
		draw = Drawing()
		draw.composite(operator='over',left=img.width - OverImg.width - 5,top=5,width=OverImg.width,height=OverImg.height,image=OverImg)
		draw(img)

                draw = Drawing()
                draw.fill_color = Color('blue')
		draw.fill_opacity = 0.5
		draw.rectangle(0,img.height - 30,img.width,img.height)
                draw(img)

		draw = Drawing()
		draw.font = 'wandtests/assets/League_Gothic.otf'
		draw.font_size = 20
		draw.fill_color = Color('white')
		draw.text_alignment = 'left'
		draw.text(5, img.height - 5, Settings['Description'])
		draw(img)

		draw = Drawing()
		draw.font = 'wandtests/assets/League_Gothic.otf'
		draw.font_size = 20
		draw.fill_color = Color('white')
		draw.text_alignment = 'right'
		draw.text(img.width - 5, img.height - 5, dt.datetime.now().strftime('%d-%m-%Y %H:%M:%S'))
		draw(img)

		img.format = 'jpeg'
		img.save(filename=Settings['FTPFile'])

#		syslog.syslog(syslog.LOG_INFO, 'Uploading Photo')
Ejemplo n.º 10
0
def banner(temp, loss, resultplt=None, date=""):
    txt_color = "white"
    with Image(width=140, height=230, background="transparent") as img:
        draw = Drawing()
        draw.font = 'font/OpenSans-Bold.ttf'
        draw.font_size = 14
        draw.font_antialias = True
        draw.text_alignment = 'center'
        draw.fill_color = txt_color
        draw.text(70, 14, 'Moscow')
        draw(img)

        draw = Drawing()
        draw.font = 'font/OpenSans-Bold.ttf'
        draw.font_size = 10
        draw.font_antialias = True
        draw.text_alignment = 'center'
        draw.fill_color = txt_color
        draw.text(70, 28, date)
        draw(img)

        draw = Drawing()
        draw.font = 'font/OpenSans-SemiBold.ttf'
        draw.font_size = 50
        draw.font_antialias = True
        draw.text_alignment = 'center'
        draw.fill_color = txt_color
        draw.text(70, 80, "%+d" % float(temp) + '°')
        draw(img)

        if resultplt:
            image_data = BytesIO()
            resultplt.axis('off')
            resultplt.gcf().set_size_inches(1.4, 0.7)
            resultplt.gcf().set_dpi(100)
            resultplt.tight_layout()
            resultplt.savefig(image_data, format='png', transparent=True)
            image_data.seek(0)
            result_image = Image(file=image_data)
            img.composite(image=result_image, left=0, top=110)

            draw = Drawing()
            draw.font = 'font/OpenSans-Bold.ttf'
            draw.font_size = 14
            draw.font_antialias = True
            draw.text_alignment = 'center'
            draw.fill_color = txt_color
            draw.text(70, 115, '2020')
            draw(img)

        for i, t in enumerate([
                "loss: " + str(loss), "input: 9 params",
                "train data: 16430 rows"
        ]):
            draw = Drawing()
            draw.font = 'font/OpenSans-Light.ttf'
            draw.font_size = 10
            draw.font_antialias = True
            draw.fill_color = txt_color
            draw.text(4, 190 + (i * 12), t)
            draw(img)

        img.save(filename='weather.png')