SVG attributes (viewbox)

  • Hi everyone!
    When exporting drawings to SVG is possible to instruct DrawBot to add the viewBox attribute?

    Thanks in advance.

  • hello @guidoferreyra,

    as far as I can tell, the SVG viewBox attribute is not written by DrawBot. but SVG is XML, so you can easily parse and modify it with Python after it has been created:

    # draw something, save as svg
    size(600, 200)
    fill(1, 0, 0)
    rect(50, 60, 200, 100)
    fill(0, 1, 0)
    oval(300, 50, 200, 200)
    stroke(0, 0, 1)
    rect(0, 0, width(), height())
    svgPath = 'svg-viewport-test.svg'
    # add viewBox attribute to <svg>
    from lxml.etree import parse
    xml = parse(svgPath)
    svg = xml.getroot()
    svg.attrib['viewBox'] = '0 0 180 150'
    xml.write(svgPath.replace('.svg', '_viewbox.svg'))

    hope this helps… cheers!

  • admin

    could elaborate why a viewBox is necessary? and how it relates to width, height DrawBot is using.

    (maybe this discussion must move to an github issue)

Log in to reply