combine common shrink code
Ted Unangst tedu@tedunangst.com
Thu, 16 Nov 2023 23:42:47 -0500
1 files changed,
18 insertions(+),
24 deletions(-)
jump to
M
backend.go
→
backend.go
@@ -90,7 +90,7 @@ }
return svg, nil } -func bigshrink(data []byte) (*image.Image, error) { +func callshrink(data []byte, params image.Params) (*image.Image, error) { if isSVG(data) { return imageFromSVG(data) }@@ -101,13 +101,8 @@ }
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, - }, + Buf: data, + Params: params, }, &res) if err != nil { return nil, err@@ -115,24 +110,23 @@ }
return res.Image, nil } -func shrinkit(data []byte) (*image.Image, error) { - if isSVG(data) { - return imageFromSVG(data) - } - cl, err := rpc.Dial("unix", backendSockname()) - if err != nil { - return nil, err +func bigshrink(data []byte) (*image.Image, error) { + params := image.Params{ + LimitSize: 14200 * 4200, + MaxWidth: 2600, + MaxHeight: 2048, + MaxSize: 768 * 1024, } - defer cl.Close() - var res ShrinkerResult - err = cl.Call("Shrinker.Shrink", &ShrinkerArgs{ - Buf: data, - Params: image.Params{LimitSize: 4200 * 4200, MaxWidth: 2048, MaxHeight: 2048}, - }, &res) - if err != nil { - return nil, err + return callshrink(data, params) +} + +func shrinkit(data []byte) (*image.Image, error) { + params := image.Params{ + LimitSize: 4200 * 4200, + MaxWidth: 2048, + MaxHeight: 2048, } - return res.Image, nil + return callshrink(data, params) } func orphancheck() {