Esempio n. 1
0
 def setUp(self):
     header = Header(text='foo', fontfullpath=None)
     linkback = Linkback(text='bar', fontfullpath=None)
     para = Paragraph(text='foo bar', fontfullpath=None)
     content = Content(para, header=header, linkback=linkback)
     fullpath = 'test.png'
     self.img = Image(content, fullpath)
Esempio n. 2
0
 def test_depending_on_opposite_to_bg_color_without_dependencies(self):
     header = Header(text='foo', fontfullpath=None, color='#000')
     linkback = Linkback(text='bar', fontfullpath=None, color='#000')
     para = Paragraph(text='foo bar', fontfullpath=None, color='#000')
     content = Content(para, header=header, linkback=linkback)
     single_unit_content = Content(para)
     self.assertFalse(content.depends_on_opposite_to_bg_color)
     self.assertFalse(single_unit_content.depends_on_opposite_to_bg_color)
Esempio n. 3
0
 def test_depending_on_opposite_to_bg_color(self):
     header = Header(text='foo', fontfullpath=None)
     linkback = Linkback(text='bar', fontfullpath=None)
     para = Paragraph(text='foo bar', fontfullpath=None)
     content = Content(para, header=header, linkback=linkback)
     single_unit_content = Content(para)
     self.assertTrue(content.depends_on_opposite_to_bg_color)
     self.assertTrue(single_unit_content.depends_on_opposite_to_bg_color)
Esempio n. 4
0
 def setUp(self):
     header = Header(text='foo', fontfullpath=None, outline=Outline())
     linkback = Linkback(text='bar', fontfullpath=None, outline=Outline())
     para = Paragraph(text='foo bar', fontfullpath=None, outline=Outline())
     content = Content(para, header=header, linkback=linkback, padding=45)
     self.fullpath = 'test.png'
     self.img = Image(content, self.fullpath)
     self.img._create_image()
     self.img._create_draw_object()
     self.img.opposite_to_bg_color = '#000'
def img_to_txt(txt, author, result):
    para = Paragraph(text=txt,
                     font=Font(roboto_font_folder + 'Roboto-Black.ttf', 30),
                     text_width=30,
                     align='center',
                     color='#ededed',
                     outline=text_outline)
    linkback = Linkback(text=author,
                        font=Font(roboto_font_folder + 'Roboto-Black.ttf', 30),
                        color='#ededed',
                        outline=text_outline)
    content = Content(paragraph=para, linkback=linkback)
    img = Image(content, fullpath=result, width=3000, height=2005)
    img.draw_on_image('bg.png')
Esempio n. 6
0
def card_gen(image, name,  fact, linkback = 'learnfacts.fun | @learnafunfact'):
    ''' Genera una tarjeta ./facts_imgs/[query]-fact.jpg a partir de  la imagen ./images/[query].jpg y el
    fact que se le envia en forma de texto. Opcional puedes agregar tu linkback pero si le mandas
    nada usa 'learnafact.fun' 
    '''

    fact_img = './facts_imgs/' + name + '-fact.png'

    roboto_font_folder = './fonts/Roboto/'
    outline = Outline(2, '#121212')
    para = Paragraph( text=fact,
        font = Font(roboto_font_folder + 'Roboto-Medium.ttf', 55),
        text_width = 30,
        align='left',
        color='#ededed', 
        outline=outline,
        )

    linkback = Linkback(text= str(linkback),
        font = Font(roboto_font_folder + 'Roboto-Bold.ttf', 18),
        color = '#ededed',
        bottom_padding = 300,
        outline=outline
        )
    content = Content(para, linkback)
    img = Image(content,
        fullpath = fact_img,
        width=1080,
        height=720
        )
    img.draw_on_image(image,
    image_enhancements=((ImageEnhance.Contrast, 0.75),
    (ImageEnhance.Brightness, 0.75)),
    image_filters=((ImageFilter.BLUR),)
    )
    return ({ 'image':image, 'fact_img': fact_img})
Esempio n. 7
0
 def test_set_content(self):
     para = Paragraph(text='foo bar', fontfullpath=None)
     content = Content(para)
     Image._set_content(self.image_mock, content)
     self.assertEqual(self.image_mock.content, content)
Esempio n. 8
0
 def setUp(self):
     header = Header(text='foo', fontfullpath=None)
     linkback = Linkback(text='bar', fontfullpath=None)
     para = Paragraph(text='foo bar', fontfullpath=None)
     self.content = Content(para, header=header, linkback=linkback)
Esempio n. 9
0
header = Header(
    text=
    'The first solar eclipse to cross America in 99 years is coming. To some, it’s an act of God.',
    font=Font(roboto_font_folder + 'Roboto-Bold.ttf', 28),
    text_width=53,
    line_padding=3,
    align='left',
    color='#ededed',
    outline=text_outline,
)

para = Paragraph(
    text=
    'Tens of millions of people are expected to cram into a narrow path, from Oregon to the Carolinas, to see the remarkable event.',
    font=Font(roboto_font_folder + 'Roboto-Medium.ttf', 25),
    text_width=60,
    align='left',
    color='#ededed',
    outline=text_outline,
)

linkback = Linkback(
    text='@washingtonpost',
    font=Font(roboto_font_folder + 'Roboto-Bold.ttf', 17),
    color='#ededed',
    outline=text_outline,
)

content = Content(para, header, linkback)

img = Image(content, fullpath='result.png', width=1080, height=720)
Esempio n. 10
0
from nider.models import Content
from nider.models import Linkback
from nider.models import Paragraph
from nider.models import Image


# TODO: change this fontpath to the fontpath on your machine
roboto_font_folder = '/home/ovd/.local/share/fonts/Roboto/'

text_outline = Outline(1, '#121212')

para = Paragraph(text='Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
                 font=Font(roboto_font_folder + 'Roboto-Medium.ttf', 25),
                 text_width=35,
                 align='center',
                 color='#efefef',
                 outline=text_outline
                 )

linkback = Linkback(text='@foobar',
                    font=Font(roboto_font_folder + 'Roboto-Bold.ttf', 20),
                    color='#efefef',
                    outline=text_outline
                    )

content = Content(paragraph=para, linkback=linkback)

img = Image(content,
            fullpath='result.png',
            width=500,
Esempio n. 11
0
def write_image_on_text(header='',
                        footer='',
                        source_path='sources/test.jpg',
                        width=1080, height=1080,
                        header_font_path='fonts/Roboto-Regular.ttf',
                        text_width_header=30,  font_size_header=40,
                        footer_font_path='fonts/Roboto-Regular.ttf',
                        font_size_footer=30, text_width_footer=30,
                        save_folder='temp/',
                        top_padding=200,
                        bottom_padding=140):
    header_text = Header(
        text=header.upper(),
        font=Font(header_font_path, font_size_header),
        text_width=text_width_header,
        align='center',
        color='#ffffff'
    )

    para = Paragraph(
        text='',
        font=Font(footer_font_path, font_size_footer),
        text_width=text_width_footer,
        align='center',
        color='#ffffff'
    )

    linkback = Linkback(
        text='',
        font=Font(footer_font_path, font_size_footer),
        align='center',
        color='#ffffff',
        bottom_padding=20
    )

    content = Content(para, header_text, linkback, padding=top_padding)

    temp_save_path = get_save_file_name(save_folder)
    img = Image(content, width=width, height=height, fullpath=temp_save_path)

    img.draw_on_texture(source_path)

    header_text = Header(
        text='',
        font=Font(header_font_path, font_size_header),
        text_width=text_width_header,
        align='center',
        color='#ffffff'
    )

    para = Paragraph(
        text=footer,
        font=Font(footer_font_path, font_size_footer),
        text_width=text_width_footer,
        align='center',
        color='#ffffff'
    )

    content = Content(para, header_text, linkback, padding=bottom_padding)

    new_save_path = get_save_file_name(save_folder)
    img = Image(content, width=width, height=height, fullpath=new_save_path)

    img.draw_on_texture(temp_save_path)

    img = Img.open(new_save_path)
    img = img.crop((0, 0, width, height))

    final_save_path = get_save_file_name(save_folder)
    img.save(final_save_path)

    return final_save_path
Esempio n. 12
0
 def setUp(self):
     header = Header(text='foo')
     linkback = Linkback(text='bar')
     para = Paragraph(text='foo bar')
     self.content = Content(para, header=header, linkback=linkback)
Esempio n. 13
0
    content_font = askopenfilename()  # selected font
    content_font = content_font.split('/')
    content_font = content_font[-1]
    print('Selected content font' + str(content_font))
    outline = Outline(2, '#121212')

    header = Header(text=head,
                    font=Font(FONTS + header_font, 60),
                    text_width=40,
                    align='left',
                    color='#ededed',
                    outline=outline)

    para = Paragraph(text=body,
                     font=Font(FONTS + content_font, 48),
                     text_width=65,
                     align='left',
                     color='#ededed',
                     outline=outline)

    linkback = Linkback(text='myQuoteSite.com |' + author,
                        font=Font(FONTS + header_font, 18),
                        color='#ededed',
                        outline=outline)

    content = Content(para, header, linkback)

    img = Image(content,
                fullpath=TOI + 'resultant_' + ti[1],
                width=1024,
                height=640)
Esempio n. 14
0
from nider.core import Font

from nider.models import Paragraph
from nider.models import Content
from nider.models import Image

# TODO: change this fontpath to the fontpath on your machine
roboto_font_folder = '/home/ovd/.local/share/fonts/Roboto/'

para = Paragraph(
    text=
    'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
    font=Font(roboto_font_folder + 'Roboto-Medium.ttf', 20),
    text_width=49,
    align='center',
    color='#121212')

content = Content(para)

img = Image(content, width=500, height=500, fullpath='result.png')

img.draw_on_bg('#efefef')
Esempio n. 15
0
# TODO: change this fontpath to the fontpath on your machine
roboto = '/home/ovd/.local/share/fonts/Roboto/'

header = Header(text='Your super interesting title!',
                fontfullpath=roboto + 'Roboto-Bold.ttf',
                fontsize=30,
                text_width=40,
                align='left',
                color='#ededed'
                )

para = Paragraph(text='Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
                 fontfullpath=roboto + 'Roboto-Medium.ttf',
                 fontsize=29,
                 text_width=65,
                 align='left',
                 color='#ededed'
                 )

linkback = Linkback(text='foo.com | @username',
                    fontfullpath=roboto + 'Roboto-Bold.ttf',
                    fontsize=24,
                    color='#ededed'
                    )

content = Content(para, header=header, linkback=linkback, padding=60)

img = TwitterPost(content,
                  fullpath='result.png',
                  )
Esempio n. 16
0
 def test_set_description_without_description_provided_but_with_para(self):
     para = Paragraph('description')
     content = Content(paragraph=para)
     Image._set_content(self.image_mock, content)
     Image._set_description(self.image_mock, '')
     self.assertEqual(self.image_mock.description, 'description')
Esempio n. 17
0
        "keywords": a,
        "limit": 25,
        "print_urls": True,
        "size": "medium"
    }
    #print(a)
    paths = response.download(arguments)
    i = 0
    for q in wikiquote.quotes(a, lang='es', max_quotes=25):

        if len(q) <= 256:

            para = Paragraph(text='"' + q + '"',
                             font=Font(
                                 roboto_font_folder + 'Roboto-Medium.ttf', 25),
                             text_width=35,
                             align='center',
                             color='#ffff00',
                             outline=text_outline)

            linkback = Linkback(text='@quienlodice',
                                font=Font(
                                    roboto_font_folder + 'Roboto-Bold.ttf',
                                    20),
                                color='#efefef',
                                outline=text_outline)

            content = Content(paragraph=para, linkback=linkback)

            img = Image(content,
                        fullpath=a + '-' + str(uuid.uuid4()) + '.png',
Esempio n. 18
0
from nider.core import Outline

from nider.models import Content
from nider.models import Linkback
from nider.models import Paragraph
from nider.models import Image

# TODO: change this fontpath to the fontpath on your machine
roboto_font_folder = '/home/ovd/.local/share/fonts/Roboto/'

text_outline = Outline(2, '#121212')

para = Paragraph(
    text=
    '“You\'ve gotta dance like there\'s nobody watching, love like you\'ll never be hurt, sing like there\'s nobody listening, and live like it\'s heaven on earth.”',
    font=Font(roboto_font_folder + 'Roboto-Bold.ttf', 35),
    text_width=30,
    align='center',
    color='#ededed',
    outline=text_outline)

linkback = Linkback(text='― William W. Purkey',
                    font=Font(roboto_font_folder + 'Roboto-Medium.ttf', 25),
                    color='#ededed',
                    outline=text_outline)

content = Content(paragraph=para, linkback=linkback)

img = Image(content, fullpath='result.png', width=500, height=750)

# TODO: change this image path to the image path on your machine
img.draw_on_image('bg.jpg')