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

(Link to open example in new tab):

Source Code (Link to Github):

# -*- coding: utf-8 -*-

import os
import sys

from visigoth import Diagram
from visigoth.common import Image, Text

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(Text("Attribution: Public Domain",url="https://en.wikipedia.org/wiki/Volcano#/media/File:MtCleveland_ISS013-E-24184.jpg",font_height=18))
html = d.draw(format="html")

f = open("example.html", "w")
f.write(html)
f.close()