resizeParams determines if the image needs to be resized, and if so, the dimensions to resize to.
(m image.Image, opt Options)
| 144 | // resizeParams determines if the image needs to be resized, and if so, the |
| 145 | // dimensions to resize to. |
| 146 | func 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 | |
| 171 | var smartcropAnalyzer = smartcrop.NewAnalyzer(nfnt.NewDefaultResizer()) |
| 172 |