Your comparison of Dianoga with the other tools isn't quite fair- though what you found is accurate. A few things to point out:
- Dianoga is lossless compression, which means as the size is reduced, the image should look identical from the version before it was run through the algorithm
- Sitecore only applies the quality setting to an image if you include resize parameters in the media request. It appears with your tests (based on my own discoveries) that you were not altering the size of the image, e.g. h=100&w=100
I created an add-on to Dianoga called Dianoga.ImageMagick that is lossy. It is available via NuGet: Just install, and build, default settings should be sufficient for most.
What it does better
It contains a few crucial changes for your use-case (and mine):
- It sets the default quality setting in Sitecore to
100
and instead alters the quality of the image as part of the ImageMagick execution. Default is 70
for JPG, 9
for PNG (highest compression)
- It properly respects the
Media.Resizing.MaxWidth
and Media.Resizing.MaxHeight
settings. Normally, these settings are only enforced on images when the image is upscaled- requested with query string params ‘h’ and ‘w’ greater than the original image. Native Sitecore will still output an image much larger than these settings if the original image exceeds the ‘MaxWidth’ or ‘MaxHeight’.
The result of Dianoga.ImageMagick is that ALL images get the same dimensional size reduction treatment if the image exceeds the ‘MaxWidth’ or ‘MaxHeight’. And all images are served with a reduced quality. In my tests it was not uncommon to go from 10+ MB to less than 1 MB for a given page with no obvious loss in image quality.
Since your question targeted PNGs, I ran a test quick with an image I created in Gimp. I intentionally applied no compression to my test image. The final size came out to 3.9 MB.
I added the image to Sitecore and ran it through the Dianoga.ImageMagick algorithm and it reduced it to 1.2 MB.
I then went back to Gimp to see how well it would do with full compression and it too reduced the image to 1.2 MB.
The beauty of using ImageMagick is that there is an enormous number of options available to meet anyone's needs: https://www.imagemagick.org/script/command-line-options.php. I have done my best to choose defaults that work for everyone, but feel free to tweak.
Relevant Settings
JPG:
<dianogaOptimizeImageMagickJpeg>
<processor type="Dianoga.ImageMagick.ImageMagickResizer, Dianoga.ImageMagick">
<ExePath>/App_Data/Dianoga Tools/imagemagick/magick.exe</ExePath>
<AdditionalImageMagick>-quality 70 -dither None -define jpeg:fancy-upsampling=off -interlace none -colorspace sRGB</AdditionalImageMagick>
</processor>
...
</dianogaOptimizeImageMagickJpeg>
PNG:
<dianogaOptimizeImageMagickPng>
<processor type="Dianoga.ImageMagick.ImageMagickResizer, Dianoga.ImageMagick">
<ExePath>/App_Data/Dianoga Tools/imagemagick/magick.exe</ExePath>
<AdditionalImageMagick>-define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1</AdditionalImageMagick>
</processor>
...
</dianogaOptimizeImageMagickPng>
Further Help
Media.Resizing.Quality
configuration item for JPEG. I believe the default is 95% which is would likely increase file size for most images.