22 May 2012

Why I love Open-Source Software

Open-source software is wonderful. For example, I needed to batch convert 700 AutoCad files (DWG) into regular image files.

Step one: Find library to do this for me. Succeeded by finding cad2svg. Can’t run as its compiled in OSX, can’t recompile b/c it has unavailable proprietary blob. Read author’s blog & README. He states that it was developed in Red Hat Linux/ Fedora. Blog is dated ~ 2009.

Off I go to grab Fedora 12. Install in virtual machine, set up shared folder between host and vboxclient. Use script like find . -name \*.dwg -print0 | xargs -0 cad2svg - OUTPUT.svg

Then jump back into OSX to use a library from Cairo 2d image library, svg2png. This will convert them into png images.

Do some googling for correct imagemagick settings to invert the image, convert all non-white to black, and then convert to monochrome.

Spent a few minutes tweaking the settings, order of events, properly piping the output image from svg2png into imagemagick… and voila! Computer is currently chugging through all 700 conversions. Command to convert from svg to png (with tweaks) svg2png -w8000 '#{item}' | convert png:- -negate -fill black +opaque white 'svgs/#{output}.png' (Note: Piping these two commands saves writing temp file to hard drive) ImageMagic, svg2png, cad2svg (except proprietary blob) are great tools made even greater by their Unix philosophy (doing one thing well and using standard-in and stdout to chain together commands)