- commit
- 0c55143
- parent
- 0365902
- author
- Eric Bower
- date
- 2022-09-26 03:17:54 +0000 UTC
feat(imgs): be more explicit about quality setting Also change resize algo to nearest neighbor
3 files changed,
+8,
-1
+4,
-0
1@@ -55,8 +55,12 @@ func (h *UploadImgHandler) metaImg(data *PostMetaData) error {
2 }
3
4 opt := shared.NewImgOptimizer(h.Cfg.Logger, "")
5+ // for small images we want to preserve quality
6+ // since it can have a dramatic effect
7 if data.FileSize < 3*MB {
8 opt.Quality = 100
9+ } else {
10+ opt.Quality = 80
11 }
12
13 contents := &bytes.Buffer{}
+3,
-0
1@@ -239,6 +239,9 @@ func imgHandler(w http.ResponseWriter, h *ImgHandler) {
2 resizeImg := h.Img.Width != 0 || h.Img.Height != 0
3
4 if h.Optimized && resizeImg {
5+ // when resizing an image we don't want to mess with quality
6+ // since that was already applied when converting to webp
7+ h.Img.Quality = 100
8 err = h.Img.Process(w, contents)
9 } else {
10 _, err = io.Copy(w, contents)
1@@ -109,7 +109,7 @@ func (h *ImgOptimizer) DecodeWebp(r io.Reader) (image.Image, error) {
2 img,
3 h.Width,
4 h.Height,
5- imaging.MitchellNetravali,
6+ imaging.NearestNeighbor,
7 ), nil
8 }
9