I have some CSS and LESS files with inline images (base64 encoded data URIs [AKA data URLs]) of which some are PNGs. I want these PNGs to be encoded using ZopfliPNGs in an automated fashion.
Sadly it seems like ZopfliPNG can only deal with with files and not e.g. with stdin/stdout (bug tracker entries like "Support piping input" are still open) which makes things a bit more complicated.
Leanify (I wrote) supports optimizing Data URI images in CSS files. It's using ZopfliPNG internally for PNG files.
It has a few advantages over your python script:
It also support other image format such as JPEG, ICO and SVG.
It does not need temporary files, everything is done in memory.
The Data URI searching has better compatibility. For CSS files, there might be '
or "
between url(
and data:image
, it also support searching in HTML and JS files which might not have url(
at all.