Implement --scale-up and --place

This commit is contained in:
Kovid Goyal
2023-01-02 10:30:27 +05:30
parent 73a055fe12
commit df06578c2d
6 changed files with 92 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"image"
"image/color"
"math"
"runtime"
"sync"
)
@@ -390,3 +391,20 @@ func PasteCenter(background image.Image, img image.Image, opaque_bg *color.NRGBA
Paste(background, img, image.Pt(x0, y0), opaque_bg)
}
func FitImage(width, height, pwidth, pheight int) (final_width int, final_height int) {
if height > pheight {
corrf := float64(pheight) / float64(height)
width, height = int(math.Floor(corrf*float64(width))), pheight
}
if width > pwidth {
corrf := float64(pwidth) / float64(width)
width, height = pwidth, int(math.Floor(corrf*float64(height)))
}
if height > pheight {
corrf := float64(pheight) / float64(height)
width, height = int(math.Floor(corrf*float64(width))), pheight
}
return width, height
}