How to load and draw SVG files?



  • Is there a simple way to load a SVG file (just as you would load an image) and display it?

    I don't need to do all kinds of editing with it, just displaying the svg in a certain size.

    I'm currently lost in all kinds of SVG modules that do all kinds of things, except just loading a simple file... Thanks!



  • I tried installing the module [svglib](https://pypi.org/project/svglib/ which is supposed to do what I want, but I end up in a maze of installing other modules and end up with errors in the lxml module.

    I'm in no way experienced in Drawbot and/or Python, so I have no idea what I'm doing... This sounds too difficult for what I'm trying to do, right?



  • hi. how about this (quick & lazy):



  • Thanks @gferreira, that works! I was just hoping to resize the image (or simply put: display the image at a certain size), but I can't find a way to do this.



  • @snaders in DrawBot you don’t really resize an image, you change the scale at which it is drawn. (same logic as in Draw a letter within a viewbox)

    imgPath = 'https://i.ytimg.com/vi/oHg5SJYRHA0/hqdefault.jpg'
    
    # get image width & height
    imgWidth, imgHeight = imageSize(imgPath)
    
    # define box width & height
    boxWidth, boxHeight = 640, 640
    
    # calculate scaling factors
    factorHeight = boxHeight / imgHeight
    factorWidth  = boxWidth  / imgWidth
    
    # draw scaled image
    with savedState():
        scale(factorWidth, factorHeight)
        image(imgPath, (0, 0))
    
    # draw box
    fill(None)
    stroke(1, 0, 0)
    strokeWidth(5)
    rect(0, 0, boxWidth, boxHeight)