SVGZ and lossy compression

last modified on 30 July 2019, by Cédric Louvrier

pingo could do lossy compression using a combination of non-scalable SVG container and JPG which should be supported even on some old browsers. this lossy transformation could be more effective on RGBA samples which have lot of colors or complex structure

N: from 1 to 100 — 1: smaller filesize, worse quality — 100: bigger filesize, better quality
pingo -svgz=N target
original file: lab.png (300.14 KB): svgz container and lossy compression
original WebP (cwebp default) pingo -svgz=16
lab - PNG lab - cwebp lab - svgz lossy
300.14 KB 66.34 KB (0.16s) 39.06 KB (0.13s)
dssim - butteraugli 0.00100984 - 3.728334 0.00082322 - 3.416768

infos

  • image data should be automatically converted to sRGB colour space if required
  • this should be compatible even on some legacy browsers (IE9, FireFox/Chrome 31, Safari 5.1, Opera 24, Android 4.4)
  • -nocompression should create svg files instead of svgz. svg files can be read directly by browsers

use svgz

svgz files can be read by some editors like GIMP or Inkscape. for web, you could need to add some instructions to serve svgz files accordingly

example on htaccess file
AddEncoding gzip .svgz
AddType image/svg+xml .svgz

you could use it as static element with the <img> tag

<img alt="desc" src="image.svgz" width="256" height="256">

compression level

note that the lossless compression level over this transformation can be increased to get smaller filesize by using -sN

N: from 0 to 9 — 0: fast and good compression — 9: slow, but better compression
pingo -svgz -sN target

related notes