Exporting SVG with transparent background


#1

hi all! i’m looking to export some very simple arcs i have as an svg. however i intend on using the file with a pcb milling machine, so i need the background to be transparent, otherwise the milling software interprets it as a fill and it will mill out a square rather than just my arcs. i thought i could do this with

ofSetBackgroundAuto(false);
ofClear(255, 255, 255, 0);

in setup, and then

if (exportSVG) ofBeginSaveScreenAsSVG("test.svg");

for (ofPolyline &arc: arcs) 
{
    arc.draw();
}

if (exportSVG)
{
    ofEndSaveScreenAsSVG();
    exportSVG = false;
}

in draw. i end up with this:

which ostensibly would be fine, but when i open this in illustrator, the background seems to be filled, and it’s something i can erase / select + delete, so it doesn’t seem like the pixels are cleared.

would be great if somebody who had more familiarity than me was able to explain what was happening! i’d like to be able to just export an svg with the transparent background straight from the app.

thanks!


#2

instead of ofClear can you try ofSetBackgroundColor() and don’t use ofSetBackgroundAuto?


#3

hi arturo! with

ofColor color = ofColor(255, 255, 255, 0);
ofSetBackgroundColor(color);

in setup, i get the same results:

test


#4

here’s a gdrive link to a short video demonstrating that the background hasn’t cleared for me. i export the svg from the app, open it in illustrator, and select + delete it.


#5

Not sure what your work flow is, but you could bring it into Illustrator and release clipping mask, ungroup and delete anything you want (including the background).


#6

hey @bakercp thanks for replying :slightly_smiling_face: i have to keep it all within openframeworks actually! would like to try to understand what’s happening here


#7

can you try using ofSetBackgroundAuto(false) and not calling any kind of background clearing?

I think this might be a bug i’ll try to take a look for next release but meanwhile you can probably disable background clear completely in ofCairoRenderer, around line 1147. just commend any line where it says cairo_paint(cr)


#8

@arturo the first suggestion didn’t seem to change anything! commenting out cairo_paint(cr) did though. here’s a screenshot of the file i was able to produce along with how it appears in the milling software:

50%20PM

so thanks for pointing me in that direction. i’m not too familiar with cairo so i’ll add this to the list of things i should read up on.


Implementing Dubins path?