How to use the pibooth.fonts.get_filename function in pibooth

To help you get started, we’ve selected a few pibooth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github werdeil / pibooth / pibooth / controls / camera.py View on Github external
def build_overlay(self, size, text, alpha):
        """Return a PIL image with the given text that can be used
        as an overlay for the camera.
        """
        image = Image.new('RGBA', size)
        draw = ImageDraw.Draw(image)
        txt_width = size[0] + 1
        i = 10
        while txt_width > size[0]:
            font = ImageFont.truetype(fonts.get_filename("Amatic-Bold.ttf"), size[1] * i // 10)
            txt_width, txt_height = draw.textsize(text, font=font)
            i -= 1

        position = ((size[0] - txt_width) // 2, (size[1] - txt_height) // 2 - size[1] // 10)
        draw.text(position, text, (255, 255, 255, alpha), font=font)
        return image
github werdeil / pibooth / pibooth / pictures / concatenate.py View on Github external
def draw_footer_text(final_image, portrait, footer_texts, footer_fonts, footer_size, text_color):
    """Draw footer text on final image.
    """
    final_width, final_height = final_image.size
    draw = ImageDraw.Draw(final_image)

    # Footer 1
    name_font = ImageFont.truetype(fonts.get_filename(footer_fonts[0]), int(2 / 3. * footer_size))
    name_width, name_height = draw.textsize(footer_texts[0], font=name_font)
    footer_x = (final_width - name_width) // 2 if portrait else final_width // 4 - name_width // 2
    footer_y = final_height - footer_size - 100 if portrait else final_height - (footer_size + name_height) // 2 - 50
    draw.text((footer_x, footer_y), footer_texts[0], text_color, font=name_font)

    # Footer 2
    date_font = ImageFont.truetype(fonts.get_filename(footer_fonts[-1]), int(1 / 3. * footer_size))
    date_width, date_height = draw.textsize(footer_texts[1], font=date_font)
    footer_x = (final_width - date_width) // 2 if portrait else 3 * final_width // 4 - date_width // 2
    footer_y = final_height - footer_size + 300 if portrait else final_height - (footer_size + date_height) // 2 - 50
    draw.text((footer_x, footer_y), footer_texts[1], text_color, font=date_font)
github werdeil / pibooth / pibooth / pictures / concatenate.py View on Github external
def draw_footer_text(final_image, portrait, footer_texts, footer_fonts, footer_size, text_color):
    """Draw footer text on final image.
    """
    final_width, final_height = final_image.size
    draw = ImageDraw.Draw(final_image)

    # Footer 1
    name_font = ImageFont.truetype(fonts.get_filename(footer_fonts[0]), int(2 / 3. * footer_size))
    name_width, name_height = draw.textsize(footer_texts[0], font=name_font)
    footer_x = (final_width - name_width) // 2 if portrait else final_width // 4 - name_width // 2
    footer_y = final_height - footer_size - 100 if portrait else final_height - (footer_size + name_height) // 2 - 50
    draw.text((footer_x, footer_y), footer_texts[0], text_color, font=name_font)

    # Footer 2
    date_font = ImageFont.truetype(fonts.get_filename(footer_fonts[-1]), int(1 / 3. * footer_size))
    date_width, date_height = draw.textsize(footer_texts[1], font=date_font)
    footer_x = (final_width - date_width) // 2 if portrait else 3 * final_width // 4 - date_width // 2
    footer_y = final_height - footer_size + 300 if portrait else final_height - (footer_size + date_height) // 2 - 50
    draw.text((footer_x, footer_y), footer_texts[1], text_color, font=date_font)
github werdeil / pibooth / pibooth / config / menu.py View on Github external
import pygame_menu as pgm
import pibooth
from pibooth import fonts
from pibooth.config.parser import DEFAULT


pgm.controls.KEY_BACK = pygame.K_ESCAPE

THEME_WHITE = pgm.themes.Theme(
    background_color=(255, 255, 255),
    scrollbar_thick=14,
    scrollbar_slider_pad=2,
    scrollbar_slider_color=(35, 149, 135),
    selection_color=(29, 120, 107),
    title_background_color=(35, 149, 135),
    title_font=fonts.get_filename("Monoid-Regular"),
    title_font_size=33,
    title_font_color=(255, 255, 255),
    widget_margin=(0, 20),
    widget_font=fonts.get_filename("Monoid-Retina"),
    widget_font_size=30,
    widget_font_color=(0, 0, 0),
)

SUBTHEME_WHITE = THEME_WHITE.copy()
SUBTHEME_WHITE.background_color = (255, 255, 255)
SUBTHEME_WHITE.scrollbar_slider_color = (252, 151, 0)
SUBTHEME_WHITE.selection_color = (241, 125, 1)
SUBTHEME_WHITE.title_background_color = (252, 151, 0)
SUBTHEME_WHITE.widget_alignment = pgm.locals.ALIGN_LEFT
SUBTHEME_WHITE.widget_margin = (40, 10)
SUBTHEME_WHITE.widget_font_size = 18
github werdeil / pibooth / pibooth / booth.py View on Github external
def initialize(self):
        """Restore the application with initial parameters defined in the
        configuration file.
        Only parameters that can be changed at runtime are restored.
        """
        # Handle the language configuration
        language.CURRENT = self.config.get('GENERAL', 'language')
        fonts.CURRENT = fonts.get_filename(self.config.gettuple('PICTURE', 'text_fonts', str)[0])

        # Set the captures choices
        choices = self.config.gettuple('PICTURE', 'captures', int)
        for chx in choices:
            if chx not in [1, 2, 3, 4]:
                LOGGER.warning("Invalid captures number '%s' in config, fallback to '%s'",
                               chx, self.capture_choices)
                choices = self.capture_choices
                break
        self.capture_choices = choices

        # Reset printed pages number
        self.printer.nbr_printed = 0

        # Handle autostart of the application
        self.config.enable_autostart(self.config.getboolean('GENERAL', 'autostart'))
github werdeil / pibooth / pibooth / booth.py View on Github external
def _initialize(self):
        """Restore the application with initial parameters defined in the
        configuration file.
        Only parameters that can be changed at runtime are restored.
        """
        # Handle the language configuration
        language.CURRENT = self._config.get('GENERAL', 'language')
        fonts.CURRENT = fonts.get_filename(self._config.gettuple('PICTURE', 'text_fonts', str)[0])

        # Set the captures choices
        choices = self._config.gettuple('PICTURE', 'captures', int)
        for chx in choices:
            if chx not in [1, 2, 3, 4]:
                LOGGER.warning("Invalid captures number '%s' in config, fallback to '%s'",
                               chx, self.capture_choices)
                choices = self.capture_choices
                break
        self.capture_choices = choices

        # Handle autostart of the application
        self._config.handle_autostart()

        self._window.arrow_location = self._config.get('WINDOW', 'arrows')
        self._window.arrow_offset = self._config.getint('WINDOW', 'arrows_x_offset')
github werdeil / pibooth / pibooth / pictures / maker.py View on Github external
def add_text(self, text, font_name, color, align=CENTER):
        """Add a new text.

        :param text: text to draw
        :type text: str
        :param font_name: name or path to font file
        :type font_name: str
        :param color: RGB tuple
        :type color: tuple
        :param align: text alignment: left, right or center
        :type align: str
        """
        assert align in [self.CENTER, self.RIGHT, self.LEFT], "Unknown aligment '{}'".format(align)
        self._texts.append((text, fonts.get_filename(font_name), color, align))
        if self.is_portrait:
            self._texts_height = 600
        else:
            self._texts_height = 300
        self._final = None  # Force rebuild