It looks like this binary searches across the Go quality levels to find acceptable quality.  This isn&#x27;t a bad idea, but it won&#x27;t be fruitful.  The Go standard library JPEG encoder is pretty basic, and reuses the quant tables from the spec.  It also doesn&#x27;t optimize the huffman tables, so the pics are typically 10% bigger than they need to be.<p>This idea, taken to the extreme is mozjpeg.  It is really advanced and can take advantage of a lot of cool tricks (like trellis optimization) in order to get the absolute best quality for the size.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;mozilla&#x2F;mozjpeg" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mozilla&#x2F;mozjpeg</a>