def test_prepare_content(self): self.img.content.header.outline = Outline() self.img.content.para.outline = Outline() self.img.content.linkback.outline = Outline() content = self.img.content self.img._prepare_content() for unit in [content.header, content.para, content.linkback]: self.assertIsNotNone(unit.color) self.assertIsNotNone(unit.outline.color)
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 test_initialization(self): outline = Outline(2, '#111') text = Text('foo', Font(), '#000', outline) self.assertEqual(text.text, 'foo') self.assertIsNotNone(text.font) self.assertEqual(text.color, (0, 0, 0)) self.assertEqual(text.outline, outline)
def test_prepare_content_with_None_units(self): self.img.content.para.outline = Outline() content = self.img.content content.header = None content.linkback = None self.img._prepare_content() self.assertIsNotNone(content.para.color) self.assertIsNotNone(content.para.outline.color)
def test_draw_unit_with_outline(self, text_mock): available_outlines = [None, Outline(2, '#111')] self.img.color = '#000' start_height = 0 aligns = ['center', 'right', 'left'] for align in aligns: for outline in available_outlines: with self.subTest(): unit = MultilineTextUnit( text='foo', fontfullpath=None, outline=outline, align=align) self.img._draw_unit(start_height, unit) self.assertTrue(text_mock.called)
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})
from PIL import ImageEnhance from PIL import ImageFilter from google_images_download import google_images_download from random import randint import sys import pdb import wikiquote import uuid # TODO: change this fontpath to the fontpath on your machine roboto_font_folder = '/home/alejo/.local/share/fonts/roboto/' text_outline = Outline(1, '#121212') autores = [ 'Julio Iglesias', 'Diego Armando Maradona', 'Carlos Menem', 'Carlos Salvador Bilardo', 'Adolf Hitler', 'Susana Gimenez', 'Hector Veira', 'Juan Domingo Perón', 'Woody Allen', 'Groucho Marx', 'Nicolas Maduro' ] for a in autores: response = google_images_download.googleimagesdownload() arguments = { "keywords": a, "limit": 25, "print_urls": True,
text = ti[0].split('*') # get author, header and content author = text[0] head = text[1] body = text[2] checker = 2 print('Chose header font') header_font = askopenfilename() # selected font header_font = header_font.split('/') header_font = header_font[-1] print('Selected header font' + str(header_font)) print('Chose content font') 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)
def test_initialization(self): outline = Outline(2, '#111') self.assertEqual(outline.width, 2) self.assertEqual(outline.color, (17, 17, 17))
def test_setting_color_without_color(self): Outline._set_color(self.outline_mock, None) self.assertIsNone(self.outline_mock.color)
def test_setting_color_with_color_provided(self): Outline._set_color(self.outline_mock, '#000') self.assertEqual(self.outline_mock.color, (0, 0, 0))
from nider.core import Font from nider.core import Outline from nider.models import Header from nider.models import Paragraph from nider.models import Linkback from nider.models import Content from nider.models import Image from PIL import ImageFilter # TODO: change this fontpath to the fontpath on your machine roboto_font_folder = '/home/ovd/.local/share/fonts/Roboto/' text_outline = Outline(2, '#111') 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),
from nider.core import Font from nider.core import Outline from nider.models import Content from nider.models import Header 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, '#efefef') header = Header(text='Google bought a service that allows patients to undergo basic clinical tests at home using smartphones.', font=Font(roboto_font_folder + 'Roboto-Bold.ttf', 22), text_width=50, align='left', color='#000100', outline=text_outline ) content = Content(header=header) img = Image(content, fullpath='result.png', width=600, height=314 ) # TODO: change this image path to the image path on your machine img.draw_on_image('bg.jpg')