How to export SVG of a specified size?

edited March 2016 in How To...

Hi all,

I've been working the the beginRecord() and endRecord() methods in Processing to export SVGs for a while now, but the SVGs I export need to be a very specific size. I've noticed that in November the size of the SVG was determined whatever was drawn between beginRecord and endRecord but since December it seems that the SVG size it always the same as the width and height of the sketch.

As a workaround I've set the size of the sketch to the exact size I need but this really limits my flexibility and keeps me from having the sketch full-screen for example. So in short:

Is there a way to export a specific area of the screen as SVG?

Thanks

Tagged:

Answers

  • edited March 2016

    I know of two ways you can do this depending on what your needs are.

    1. you can save to a pgraphics object using [name of pgraphic].beginRecord() so if you're able to render the section you want in an svg as a pgraphic I would do that.
    2. if you're not able to do that you can rerender the whole screen as an svg and then use processing to crop that svg by calling shape on a pgraphic of the size of your desired svg. (maybe before background so the user doesn't seen it)

    (3. you can also use a few outside programs to edit the svg after the fact. I've personally used python to crop my files.)

  • Ah, using PGraphics sounds like a good way to go. I've been trying to add a beginRecord() and endRecord() to the CreateGraphics example but there doesn't appear to be a function beginRecord which I can call on a pgraphic object. Is this still available in Processing 3? Thanks

  • Answer ✓

    Eventually chose not to go down the PGraphics route and did a workaround instead. I've set the sketch resolution to have the same ratio as the area I'm exporting and upon export scale that area to the entire screen. Does not give me maximum flexibility but it works fine.

Sign In or Register to comment.