From 0dd17d00386e1666c51f4761c1d6706b73d6b231 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 27 Aug 2023 15:25:58 -0400 Subject: [PATCH] a bigger shrinker for uploads --- backend.go | 25 +++++++++++++++++++++++++ web.go | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/backend.go b/backend.go index 19b260f..2d20874 100644 --- a/backend.go +++ b/backend.go @@ -83,6 +83,31 @@ func imageFromSVG(data []byte) (*image.Image, error) { return svg, nil } +func bigshrink(data []byte) (*image.Image, error) { + if isSVG(data) { + return imageFromSVG(data) + } + cl, err := rpc.Dial("unix", backendSockname()) + if err != nil { + return nil, err + } + defer cl.Close() + var res ShrinkerResult + err = cl.Call("Shrinker.Shrink", &ShrinkerArgs{ + Buf: data, + Params: image.Params{ + LimitSize: 14200 * 4200, + MaxWidth: 2600, + MaxHeight: 2048, + MaxSize: 768 * 1024, + }, + }, &res) + if err != nil { + return nil, err + } + return res.Image, nil +} + func shrinkit(data []byte) (*image.Image, error) { if isSVG(data) { return imageFromSVG(data) diff --git a/web.go b/web.go index 16c6a1d..398cbde 100644 --- a/web.go +++ b/web.go @@ -1650,7 +1650,7 @@ func formtodonk(w http.ResponseWriter, r *http.Request, filehdr *multipart.FileH file.Close() data := buf.Bytes() var media, name string - img, err := shrinkit(data) + img, err := bigshrink(data) if err == nil { data = img.Data format := img.Format