Example #1
0
def build_avatar_component(path, icon_size=None, avatar_size=None):
    from .models import BaseAvatar
    icon_size = icon_size or BaseAvatar.ICON_SIZE
    avatar_component_size = avatar_size or (899.2, 1415.7)
    scale_factor = icon_size[1] / avatar_component_size[1]
    x_to_center = (icon_size[0] / 2) - (
        (avatar_component_size[0] * scale_factor) / 2)
    svg = SVG(f'{COMPONENT_BASE}{path}')
    if path.startswith('Wallpaper') or path.startswith('Makeup'):
        src = transform.fromfile(f'{COMPONENT_BASE}{path}')

        if src.width is not None:
            src_width = float(re.sub('[^0-9]', '', src.width))
        else:
            src_width = 900

        if src.height is not None:
            src_height = float(re.sub('[^0-9]', '', src.height))
        else:
            src_height = 1415
        scale_factor = icon_size[1] / src_height
        if path.startswith('Makeup'):
            scale_factor = scale_factor / 2

        svg = svg.scale(scale_factor)
        if path.startswith('Makeup'):
            x_to_center = (icon_size[0] / 2) - ((src_width * scale_factor) / 2)
            svg = svg.move(x_to_center, src_height * scale_factor / 2)

    if not path.startswith('Wallpaper') and not path.startswith('Makeup'):
        svg = svg.scale(scale_factor)
        svg = svg.move(x_to_center, 0)
    return svg
Example #2
0
def build_avatar_component(path, icon_size=None, avatar_size=None):
    icon_size = icon_size or (215, 215)
    avatar_component_size = avatar_size or (899.2, 1415.7)
    scale_factor = icon_size[1] / avatar_component_size[1]
    x_to_center = (icon_size[0] / 2) - ((avatar_component_size[0] * scale_factor) / 2)
    svg = SVG(f'{COMPONENT_BASE}{path}')
    if path.startswith('Wallpaper'):
        src = transform.fromfile(f'{COMPONENT_BASE}{path}')

        #       TODO: Consider width aswell...
        #        if src.width != None:
        #            src_width = float(re.sub('[^0-9]','', src.width))
        #        else:
        #            src_width = 900

        if src.height is not None:
            src_height = float(re.sub('[^0-9]', '', src.height))
        else:
            src_height = 1415
        scale_factor = icon_size[1] / src_height
        svg = svg.scale(scale_factor)
    if not path.startswith('Wallpaper'):
        svg = svg.scale(scale_factor)
        svg = svg.move(x_to_center, 0)
    return svg