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')
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_proper_inheritance(self, T_mock, AM_mock, _set_height_mock): font = Font() unit = SingleLineTextUnit(text='foo', font=font, color='#000', outline=None, align='center') T_mock.assert_called_once_with(unit, text='foo', font=font, color='#000', outline=None) AM_mock.assert_called_once_with(unit, align='center')
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})
def test_proper_inheritance(self, T_mock, MTM_mock): font = Font() multiline_text = MultilineText(text='foo', font=font, color='#000', outline=None, text_width=20, line_padding=5) T_mock.assert_called_once_with(multiline_text, text='foo', font=font, color='#000', outline=None) MTM_mock.assert_called_once_with(multiline_text, text_width=20, line_padding=5)
def test_proper_inheritance(self, MT_mock, AM_mock, _set_unit_mock): font = Font() unit = MultilineTextUnit(text='foo', font=font, color='#000', outline=None, text_width=20, line_padding=5, align='center') MT_mock.assert_called_once_with(unit, text='foo', font=font, color='#000', outline=None, text_width=20, line_padding=5) AM_mock.assert_called_once_with(unit, align='center')
def _adjust_fontsize(self, bg_image): text_width, text_height = self.font.getsize(self.text) angle = self.rotate_angle # If the width of the image is bigger than the height of the image and we rotate # our watermark it may go beyond the bounding box of the original image, # that's why we need to take into consideration the actual width of the rotated # waterwark inside the original image's bounding box bg_image_w, bg_image_h = bg_image.size if angle and (bg_image_w > bg_image_h): max_wm_w = 2 * \ abs(bg_image_h / (2 * math.sin(math.radians(angle)))) else: max_wm_w = bg_image_w while text_width + text_height < max_wm_w: self.font_object = Font(self.font_object.path, self.font_object.size + 1) self.font = self.font_object.font text_width, text_height = self.font.getsize(self.text)
def test_watermark_initialization_with_default_font(self): with self.assertRaises(ImageGeneratorException): Watermark(text='foo', font=Font())
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')
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) linkback = Linkback(text='myQuoteSite.com |' + author, font=Font(FONTS + header_font, 18), color='#ededed',
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 TwitterPost # TODO: change this fontpath to the fontpath on your machine roboto_font_folder = '/home/ovd/.local/share/fonts/Roboto/' outline = Outline(2, '#121212') header = Header(text='Your super interesting title!', font=Font(roboto_font_folder + 'Roboto-Bold.ttf', 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.', font=Font(roboto_font_folder + 'Roboto-Medium.ttf', 29), text_width=65, align='left', color='#ededed') linkback = Linkback(text='foo.com | @username', font=Font(roboto_font_folder + 'Roboto-Bold.ttf', 24), color='#ededed')
def test_set_height(self): unit = SingleLineTextUnit('foo', Font()) # height of the default font self.assertEqual(unit.height, 11)
from nider.core import Font from nider.models import Paragraph from nider.models import Watermark from nider.models import Content from nider.models import Image # TODO: change this fontpath to the fontpath on your machine fonts_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(fonts_folder + 'Roboto-Medium.ttf', 20), text_width=49, align='center', color='#121212' ) watermark = Watermark(text='COPYRIGHT', font=Font(fonts_folder + 'Roboto-Medium.ttf'), color='#111', cross=True ) content = Content(para, watermark=watermark) img = Image(content, width=500, height=500, fullpath='result.png', )
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
def test_initialization(self): font = Font() self.assertIsNotNone(font.font)
def test_setting_font(self): self.font_mock.path = 'foo/bar' self.font_mock.size = 23 Font._set_font(self.font_mock) self.assertIsNotNone(self.font_mock.font)
def test_set_height(self): unit = MultilineTextUnit(text='Lorem imsup dolor si amet', font=Font(), text_width=5, line_padding=6) self.assertEqual(unit.height, 79)
def test_set_unit(self, _set_height_mock): unit = MultilineTextUnit(text='Lorem imsup dolor si amet', font=Font(), text_width=5) self.assertEqual(unit.wrapped_lines, ['Lorem', 'imsup', 'dolor', 'si', 'amet'])
response = google_images_download.googleimagesdownload() arguments = { "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,
from nider.core import Font from nider.models import Watermark from nider.tools import add_watermark # TODO: change this fontpath to the fontpath on your machine roboto_fonts_folder = '/home/ovd/.local/share/fonts/Roboto/' watermark = Watermark(text='COPYRIGHT', font=Font(roboto_fonts_folder + 'Roboto-Medium.ttf', 20), color='#111', cross=True) add_watermark('bg.jpg', watermark, 'result.jpg')