Image

class visigoth.common.image.Image(mime_type='', content_bytes=[], path_or_url='', width=0, height=0, scale=1.0, tooltip='')

Create an Image (gif,png and jpeg formats are supported)

Keyword Arguments
  • mime_type (str) – the mime type (either image/png, image/jpeg or image/gif)

  • content_bytes (list) – list with the raw bytes of the image

  • path_or_url (str) – the path or URL to the image file

  • width (int) – the width of the image in bytes

  • height (int) – the height of the image in bytes

  • scale (float) – used to scale the image

  • tooltip (str) – a tooltip to display when hovering over the image

Notes

Caller must provide EITHER path_or_url OR (content_bytes AND mimeType) If width and height are not provided they will be extracted from the image

Example

Screenshot (Link to open SVG for interactive features):

../_images/example10.png

Source Code (Link to Github):


import os
import sys
import argparse

from visigoth.diagram import Diagram
from visigoth.common.image import Image
from visigoth.common.text import Text

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    folder = os.path.split(sys.argv[0])[0]

    d = Diagram(fill="white")
    d.add(Image(mime_type="image/jpeg",content_bytes=open(os.path.join(folder,"MtCleveland.jpg"),"rb").read(),tooltip="MtCleveland Volcano Eruption"))
    d.add(Image(scale=2.0,path_or_url=os.path.join(folder,"MtCleveland.png"),tooltip="MtCleveland Volcano Eruption"))
    d.add(Image(scale=0.5,mime_type="image/gif",content_bytes=open(os.path.join(folder,"MtCleveland.gif"),"rb").read(),tooltip="MtCleveland Volcano Eruption"))
    # d.add(Image(path_or_url="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/MtCleveland_ISS013-E-24184.jpg/320px-MtCleveland_ISS013-E-24184.jpg",tooltip="MtCleveland Volcano Eruption"))
    d.add(Text("Attribution: Public Domain",url="https://en.wikipedia.org/wiki/Volcano#/media/File:MtCleveland_ISS013-E-24184.jpg",font_height=18))
    svg = d.draw()

    f = open(args.outpath, "wb")
    f.write(svg)
    f.close()