- commit
- 5fbb376
- parent
- aa2149e
- author
- Eric Bower
- date
- 2023-03-16 01:50:32 +0000 UTC
bug(imgs): ensure webp imgs are saved Also in this commit is a change to the resize filter algorithm to see if that helps with quality and performance. Read more: https://github.com/disintegration/imaging#image-resizing
3 files changed,
+11,
-5
+3,
-3
1@@ -80,14 +80,13 @@ func (h *UploadImgHandler) metaImg(data *PostMetaData) error {
2 contents := &bytes.Buffer{}
3
4 img, err := shared.GetImageForOptimization(tee, data.MimeType)
5- finalName := data.Filename
6+ finalName := shared.SanitizeFileExt(data.Filename)
7 if errors.Is(err, shared.AlreadyWebPError) {
8 h.Cfg.Logger.Infof("(%s) is already webp, skipping encoding", data.Filename)
9- finalName = fmt.Sprintf("%s.webp", shared.SanitizeFileExt(finalName))
10+ finalName = fmt.Sprintf("%s.webp", finalName)
11 webpReader = tee
12 } else if err != nil {
13 h.Cfg.Logger.Infof("(%s) is a file format (%s) that we cannot convert to webp, skipping encoding", data.Filename, data.MimeType)
14- finalName = shared.SanitizeFileExt(finalName)
15 webpReader = tee
16 } else {
17 err = opt.EncodeWebp(contents, img)
18@@ -95,6 +94,7 @@ func (h *UploadImgHandler) metaImg(data *PostMetaData) error {
19 return err
20 }
21
22+ finalName = fmt.Sprintf("%s.webp", finalName)
23 webpReader = bytes.NewReader(contents.Bytes())
24 }
25
+7,
-1
1@@ -233,7 +233,13 @@ func imgHandler(w http.ResponseWriter, h *ImgHandler) {
2
3 contents, err := h.Storage.GetFile(bucket, fname)
4 if err != nil {
5- h.Logger.Infof("file not found in storage %s/%s", h.Username, post.Filename)
6+ h.Logger.Infof(
7+ "file not found %s/%s in storage (bucket: %s, name: %s)",
8+ h.Username,
9+ post.Filename,
10+ bucket.Name,
11+ fname,
12+ )
13 http.Error(w, err.Error(), http.StatusInternalServerError)
14 return
15 }
1@@ -141,7 +141,7 @@ func (h *ImgOptimizer) DecodeWebp(r io.Reader) (image.Image, error) {
2 img,
3 h.Width,
4 h.Height,
5- imaging.NearestNeighbor,
6+ imaging.CatmullRom,
7 ), nil
8 }
9