a bigger shrinker for uploads

This commit is contained in:
Ted Unangst 2023-08-27 15:25:58 -04:00
parent 1b36e72cc1
commit 0dd17d0038
2 changed files with 26 additions and 1 deletions

View File

@ -83,6 +83,31 @@ func imageFromSVG(data []byte) (*image.Image, error) {
return svg, nil 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) { func shrinkit(data []byte) (*image.Image, error) {
if isSVG(data) { if isSVG(data) {
return imageFromSVG(data) return imageFromSVG(data)

2
web.go
View File

@ -1650,7 +1650,7 @@ func formtodonk(w http.ResponseWriter, r *http.Request, filehdr *multipart.FileH
file.Close() file.Close()
data := buf.Bytes() data := buf.Bytes()
var media, name string var media, name string
img, err := shrinkit(data) img, err := bigshrink(data)
if err == nil { if err == nil {
data = img.Data data = img.Data
format := img.Format format := img.Format