diff --git a/main.go b/main.go index ec02450..a08d899 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,7 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) { } if forbidden { writeError(w, imgPath, method, "size is not allowed", http.StatusForbidden) + return } size := strings.Split(args, "x") @@ -90,6 +91,7 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) { return } + // Read from response body, convert and write to output buffer img, err := vips.NewImageFromReader(resp.Body) if err != nil { writeError(w, imgPath, method, fmt.Sprintf("%v", err), http.StatusInternalServerError) @@ -100,28 +102,14 @@ func resizeHandler(w http.ResponseWriter, r *http.Request) { writeError(w, imgPath, method, fmt.Sprintf("%v", err), http.StatusInternalServerError) return } - ep := vips.NewDefaultExportParams() + ep := vips.NewDefaultExportParams() // default export params are sufficient buf, _, _ := img.Export(ep) _, err = w.Write(buf) if err != nil { writeError(w, imgPath, method, fmt.Sprintf("%v", err), http.StatusInternalServerError) return } - - // govips returns the output of the image as a []byte object. We don't need - // it since we are directly piping it to the ResponseWriter - /*_, _, err = vips.NewTransform(). - Load(resp.Body). - ResizeStrategy(vips.ResizeStrategyAuto). - Resize(iw, ih). - Output(w). - Apply() - - if err != nil { - writeError(w, imgPath, method, "failed to resize", http.StatusInternalServerError) - return - } - */ + case "thumbnail":