MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / calcSizes

Method calcSizes

processing/prepare.go:175–221  ·  view source on GitHub ↗
(widthToScale, heightToScale int, po ProcessingOptions)

Source from the content-addressed store, hash-verified

173}
174
175func (c *Context) calcSizes(widthToScale, heightToScale int, po ProcessingOptions) {
176 c.TargetWidth = imath.Scale(po.Width(), c.DprScale*po.ZoomWidth())
177 c.TargetHeight = imath.Scale(po.Height(), c.DprScale*po.ZoomHeight())
178
179 c.ScaledWidth = imath.Scale(widthToScale, c.WScale)
180 c.ScaledHeight = imath.Scale(heightToScale, c.HScale)
181
182 if po.ResizingType() == ResizeFillDown && !po.Enlarge() {
183 diffW := float64(c.TargetWidth) / float64(c.ScaledWidth)
184 diffH := float64(c.TargetHeight) / float64(c.ScaledHeight)
185
186 switch {
187 case diffW > diffH && diffW > 1.0:
188 c.ResultCropHeight = imath.Scale(c.ScaledWidth, float64(c.TargetHeight)/float64(c.TargetWidth))
189 c.ResultCropWidth = c.ScaledWidth
190
191 case diffH > diffW && diffH > 1.0:
192 c.ResultCropWidth = imath.Scale(c.ScaledHeight, float64(c.TargetWidth)/float64(c.TargetHeight))
193 c.ResultCropHeight = c.ScaledHeight
194
195 default:
196 c.ResultCropWidth = c.TargetWidth
197 c.ResultCropHeight = c.TargetHeight
198 }
199 } else {
200 c.ResultCropWidth = c.TargetWidth
201 c.ResultCropHeight = c.TargetHeight
202 }
203
204 if po.ExtendAspectRatioEnabled() && c.TargetWidth > 0 && c.TargetHeight > 0 {
205 outWidth := imath.MinNonZero(c.ScaledWidth, c.ResultCropWidth)
206 outHeight := imath.MinNonZero(c.ScaledHeight, c.ResultCropHeight)
207
208 diffW := float64(c.TargetWidth) / float64(outWidth)
209 diffH := float64(c.TargetHeight) / float64(outHeight)
210
211 switch {
212 case diffH > diffW:
213 c.ExtendAspectRatioHeight = imath.Scale(outWidth, float64(c.TargetHeight)/float64(c.TargetWidth))
214 c.ExtendAspectRatioWidth = outWidth
215
216 case diffW > diffH:
217 c.ExtendAspectRatioWidth = imath.Scale(outHeight, float64(c.TargetWidth)/float64(c.TargetHeight))
218 c.ExtendAspectRatioHeight = outHeight
219 }
220 }
221}
222
223func (c *Context) limitScale(widthToScale, heightToScale int, po ProcessingOptions) {
224 maxresultDim := c.PO.MaxResultDimension()

Callers 2

limitScaleMethod · 0.95
CalcParamsMethod · 0.95

Calls 9

ScaleFunction · 0.92
MinNonZeroFunction · 0.92
ZoomWidthMethod · 0.80
ZoomHeightMethod · 0.80
ResizingTypeMethod · 0.80
EnlargeMethod · 0.80
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected