Make a drawing (lines, circles, text) and save as an image file?

(John Gabriele) #1

How can I use Haxe to make a drawing (I need to programmatically specify lines, maybe other shapes, and some text, providing x and y coordinates, sizes, etc.) and then save it as an image file (possibly png or ppm) on disk?

I don’t need a GUI — this is for a command line program.


(Mark) #2

Some options:

(John Gabriele) #3

Thanks, Mark.

It’s occurred to me that I can also manually create an svg file. Looking into .

(tokiop) #4

Hi !

Some SVG creation helpers have been discussed in this thread.

For rendering, the svg lib and maybe vectorasset might help to output a bitmap - not sure it works on the commandline.

It might be simpler to output the svg and render it as a second step with an external program/process. I use inkscape like this :

Sys.command("inkscape", [
	"--export-png", 'output/path/name.png',
	"--export-dpi", '96',
	"--export-background", "ffffff"

Would be interested in you findings ! :slight_smile:

(John Gabriele) #5

Thanks, tokiop.

Looks like I don’t actually need a png file — I want a printed copy, and can just open the svg file in my browser and print it from there.

Will see what I can come up with!

(Mike Robinson) #6

If what you need is “lines, circles and text,” I think that SVG is always the best way to go because it will be rendered on-the-spot based on the vector-graphics drawing commands contained in the file. The files are tiny, and the output resolution is of course as high as it can be.

I use “Inkscape” to build and manage SVG files.