def update(self, value=None): text = Text(value or self.text.get()) ratio = 0 match = None for template in self.app.template_service.all(): _ratio, path = template.match(str(text).lower()) if _ratio > ratio: ratio = _ratio log.info("Matched at %s: %s - %s", ratio, template, path) match = template, Text(path) if match: domain = self.app.image_service.create(*match) image = Image.open(domain.path) old_size = image.size max_size = self.root.winfo_width(), self.root.winfo_height() ratio = min(max_size[0] / old_size[0], max_size[1] / old_size[1]) new_size = [int(s * ratio * 0.9) for s in old_size] image = image.resize(new_size, Image.ANTIALIAS) self._image = ImageTk.PhotoImage(image) self.label.configure(image=self._image) self.clear() self.restart(update=True, clear=False)
def main(): logging.info("Generating sample images...") app = create_app(ProdConfig) with app.app_context(): for template in app.template_service.all(): app.image_service.create(template, Text("_")) app.image_service.create(template, Text("_/_")) app.image_service.create(template, template.sample_text)
def test_2_slashes(self): text = Text("foo/bar/qux") assert "FOO" == text.top assert "BAR" == text.bottom assert "QUX" == text.get_line(2) assert "" == text.get_line(3)
def main(): log.info("Generating sample images...") app = create_app(ProdConfig) with app.app_context(): for template in app.template_service.all(): for text in [Text("_"), template.sample_text]: for watermark in ["", "memegen.link"]: app.image_service.create(template, text, watermark=watermark)
def run(): app = create_app(ProductionConfig) with app.app_context(): options = [] for template in app.template_service.all(): for text in [Text("_"), template.sample_text]: for watermark in ["", "memegen.link"]: options.append((template, text, watermark)) print(f"Generating {len(options)} sample images...") for template, text, watermark in options: app.image_service.create(template, text, watermark=watermark)
def test_lines_strip_spaces(self): text = Text(" hello World / ") assert ["HELLO WORLD"] == text.lines
def test_lines_ignore_capital_after_sep(self): text = Text("hello-World") assert ["HELLO WORLD"] == text.lines
def test_empty_is_falsey(self): assert False is bool(Text())
def test_init_0_slashes(self): text = Text("foo") assert "FOO" == text.top assert "" == text.bottom
def test_path_with_a_single_underscore(self): text = Text(" _ ") assert "_" == text.path
def test_path_with_case_changes(self): text = Text("withCaseChanges/InIT") assert "with-case-changes/in-it" == text.path
def test_path_with_dashes(self): text = Text("with-dashes/in-it") assert "with-dashes/in-it" == text.path
def test_lines_split_underscore_as_spaces(self): text = Text("hello_world") assert ["HELLO WORLD"] == text.lines
def test_init_1_slash(self): text = Text("foo/bar") assert "FOO" == text.top assert "BAR" == text.bottom assert "" == text.get_line(2)
def test_no_space_after_apostrophe(self): text = Text("that'd be great") assert ["THAT'D BE GREAT"] == text.lines
def test_ignore_capital_after_apostrophe(self): text = Text("Y'ALL") assert ["Y'ALL"] == text.lines
def test_case_ignored_after_space(self): text = Text("HELLO WORLD") assert ["HELLO WORLD"] == text.lines
def test_split_dash_as_spaces(self): text = Text("hello-world") assert ["HELLO WORLD"] == text.lines
def test_only_spaces_is_falsey(self): assert False is bool(Text("_/_/_"))
def test_duplicate_capitals_treated_as_spaces(self): text = Text("IWantTHISPattern_to-Work") assert ["I WANT THIS PATTERN TO WORK"] == text.lines
def test_path(self): text = Text("hello/World") assert "hello/world" == text.path
def test_lines_split_underscore_as_spaces_ignores_case(self): text = Text("HELLO WORLD") assert ["HELLO WORLD"] == text.lines
def test_path_with_underscores(self): text = Text("with_underscores/in_it") assert "with-underscores/in-it" == text.path
def test_lines_split_case_as_spaces(self): text = Text("helloWorld") assert ["HELLO WORLD"] == text.lines
def test_path_strips_spaces(self): text = Text(" with spaces/ in it / ") assert "with--spaces/in-it" == text.path
def test_lines_keep_spaces(self): text = Text("hello world") assert ["HELLO WORLD"] == text.lines
def test_path_with_duplicate_capitals(self): text = Text("IWantTHISPattern_to-Work") assert "i-want-this-pattern-to-work" == text.path
def test_lines_ignore_initial_capital(self): text = Text("HelloWorld") assert ["HELLO WORLD"] == text.lines
def test_init_none(self): text = Text() assert "" == text.top assert "" == text.bottom
def test_content_is_truthy(self): assert True is bool(Text("Hello, world!"))