I would like to optimize a SVG using software on Ubuntu (and by optimize I mean to reduce the file size without loosing any visible parts of the graphic) and I do mean software I know there are some websites that can do this but I don't trust my internet connection always being good enough for this to work for me. I would also like to keep the file format SVG, I know that SVGZ is usually substantially smaller than its uncompressed counterpart but I am uploading these SVGs to a local MediaWiki installation and it cannot thumbnail SVGZ files to my knowledge (if I'm wrong please do correct me).

  • What about inkscape? – Maythux Jun 18 '15 at 14:16
  • If you have a command-line way of doing that using Inkscape, with minimal user input required (like I don't want to have to try half a dozen different compression methods/options to get the best results) that sounds acceptable as an answer to me :). – Josh Pinto Jun 18 '15 at 14:17
  • I dont know command line, use the GUI app, take a look for y3x.ru/2012/08/inkscape-optimization-tips – Maythux Jun 18 '15 at 14:18
  • github.com/svg/svgo – Bruni Jun 18 '15 at 14:26
  • look to my answer – Maythux Jun 18 '15 at 14:26

I can't think of something better than inkscape.

Inkscape is an open-source vector graphics editor similar to Adobe Illustrator, Corel Draw, Freehand, or Xara X. What sets Inkscape apart is its use of Scalable Vector Graphics (SVG), an open XML-based W3C standard, as the native format.

You can install it usind command:

sudo apt-get install inkscape

Take a look for this link for tips to optimize SVG using inkscape.

for comamnd line I think you should take a look for scour

scour --help
scour 0.26
Copyright Jeff Schiller, Louis Simard, 2010
Usage: scour [-i input.svg] [-o output.svg] [OPTIONS]

If the input/output files are specified with a svgz extension, then compressed
SVG is assumed. If the input file is not specified, stdin is used. If the
output file is not specified,  stdout is used.

  --version                   show program's version number and exit
  -h, --help                  show this help message and exit
  --disable-simplify-colors   won't convert all colors to #RRGGBB format
  --disable-style-to-xml      won't convert styles into XML attributes
  --disable-group-collapsing  won't collapse <g> elements
  --create-groups             create <g> elements for runs of elements with
                              identical attributes
  --enable-id-stripping       remove all un-referenced ID attributes
  --enable-comment-stripping  remove all <!-- --> comments
  --shorten-ids               shorten all ID attributes to the least number of
                              letters possible
  --disable-embed-rasters     won't embed rasters as base64-encoded data
  --keep-editor-data          won't remove Inkscape, Sodipodi or Adobe
                              Illustrator elements and attributes
  --remove-metadata           remove <metadata> elements (which may contain
                              license metadata etc.)
  --renderer-workaround       work around various renderer bugs (currently
                              only librsvg) (default)
  --no-renderer-workaround    do not work around various renderer bugs
                              (currently only librsvg)
  --strip-xml-prolog          won't output the <?xml ?> prolog
  --enable-viewboxing         changes document width/height to 100%/100% and
                              creates viewbox coordinates
  -p DIGITS, --set-precision=DIGITS
                              set number of significant digits (default: 5)
  -q, --quiet                 suppress non-error output
  --indent=INDENT_TYPE        indentation of the output: none, space, tab
                              (default: space)
  --protect-ids-noninkscape   Don't change IDs not ending with a digit
                              Don't change IDs given in a comma-separated list
                              Don't change IDs starting with the given prefix

Also take a look for this SE question , it may help.

| improve this answer | |
  • Um, I just gave it a try on some SVGs I generated using MarvinSketch, a chemical structure editor and it didn't optimize it, so I'm guessing this optimization is based on the assumption the SVG was made in Inkscape. I have used Inkscape before, in fact I frequently use it to remove whitespace from these SVGs but I can't seem to get rid of certain info in the XML markup code that's unnecessary. Here's an example SVG in my Google Drive if you'd like something to test your methods with: goo.gl/PbnZgN. – Josh Pinto Jun 18 '15 at 14:35
gzip -S z ./examples/*/*.svg

See https://lists.w3.org/Archives/Public/www-svg/2007Apr/0025.html

| improve this answer | |

Use svgo https://spin.atomicobject.com/2016/11/10/svgo-compressing-svg-images/

Works quickly and provides a summary of results

You can use it using the same file for input & output, or not.

# svgo file.svg -o file.svg
Done in 268 ms!
67.819 KiB - 1.7% = 66.669 KiB

Don't be fooled by that small reduction. It is the second pass over already compressed files. On the first round the average saving was 65% (images created with gnuplot).

I just discovered it today and I'm very satisfied.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.