MCPcopy
hub / github.com/willnorris/imageproxy / resizeParams

Function resizeParams

transform.go:146–169  ·  view source on GitHub ↗

resizeParams determines if the image needs to be resized, and if so, the dimensions to resize to.

(m image.Image, opt Options)

Source from the content-addressed store, hash-verified

144// resizeParams determines if the image needs to be resized, and if so, the
145// dimensions to resize to.
146func resizeParams(m image.Image, opt Options) (w, h int, resize bool) {
147 // convert percentage width and height values to absolute values
148 imgW := m.Bounds().Dx()
149 imgH := m.Bounds().Dy()
150 w = evaluateFloat(opt.Width, imgW)
151 h = evaluateFloat(opt.Height, imgH)
152
153 // never resize larger than the original image unless specifically allowed
154 if !opt.ScaleUp {
155 if w > imgW {
156 w = imgW
157 }
158 if h > imgH {
159 h = imgH
160 }
161 }
162
163 // if requested width and height match the original, skip resizing
164 if (w == imgW || w == 0) && (h == imgH || h == 0) {
165 return 0, 0, false
166 }
167
168 return w, h, true
169}
170
171var smartcropAnalyzer = smartcrop.NewAnalyzer(nfnt.NewDefaultResizer())
172

Callers 2

transformImageFunction · 0.85
TestResizeParamsFunction · 0.85

Calls 1

evaluateFloatFunction · 0.85

Tested by 1

TestResizeParamsFunction · 0.68