Example #1
0
def prepare_character_images(drawing):
    # Load images base64 encoded to embed into svg file
    character_images = dict()

    for index in range(0, 84):
        p = Pattern(x=0,
                    y=0,
                    width="100%",
                    height="100%",
                    viewBox="0 0 512 512")
        image_path = ROOT_PATH_IMAGES + str(index) + ".jpeg"

        # Loading the image an convert it to base64 to integrate it directly
        # into the graphic.
        base64_prefix_href = "data:image/jpeg;base64,"
        with open(image_path, 'rb') as image:
            base64_encoded_string = base64.standard_b64encode(image.read())
        href_base64_img = base64_prefix_href + base64_encoded_string.decode(
            'utf-8')

        i = Image(href=href_base64_img, x="0%", y="0%", width=512, height=512)
        p.add(i)
        drawing.defs.add(p)
        character_images[index] = p

    return character_images
Example #2
0
 def __init__(self):
     super().__init__()
     rect = Rect(insert=(0, 0), size=(5, 5), fill='#9e9e9e')
     path = Path('M 0 5 L 5 0 Z M 6 4 L 4 6 Z M -1 1 L 1 -1 Z',
                 stroke='#888', stroke_width=1)
     pattern = Pattern(id=self.__class__.__name__.lower(),
                       patternUnits='userSpaceOnUse',
                       size=(5, 5), stroke='none')
     pattern.add(rect)
     pattern.add(path)
     self.add(pattern)