File: clickable_image.py

package info (click to toggle)
svgwrite 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 2,092 kB
  • sloc: python: 12,603; makefile: 117; sh: 5
file content (27 lines) | stat: -rw-r--r-- 819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3

import svgwrite

MAX_PIXELS = 1000


def clickable_image(dwg, image_href, dest_href, insert=None, size=None):
    insert = insert or ("0%", "0%")
    size = size or ("100%", "100%")
    dwg.add(dwg.a(href=dest_href)).add(dwg.image(image_href, insert=insert, size=size))


def make_drawing(filename="clickable_image.svg"):
    dwg = svgwrite.Drawing(filename, size=(MAX_PIXELS, MAX_PIXELS))
    dwg.viewbox(0, 0, MAX_PIXELS, MAX_PIXELS)
    dwg.add(dwg.rect(size=('100%', '100%'), fill="lightgrey", class_='background'))

    clickable_image(dwg,
                    image_href="https://github.com/fluidicon.png",
                    dest_href"https://github.com/mozman/svgwrite",
                    insert=("25%", "25%"), size=("50%", "50%"))

    return dwg


make_drawing().save(pretty=True)