|
@@ -259,9 +259,8 @@ func Fit(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA
|
|
|
return Resize(img, newW, newH, filter)
|
|
|
}
|
|
|
|
|
|
-// Fill scales the image to the smallest possible size that will cover the specified dimensions,
|
|
|
-// crops the resized image to the specified dimensions using the given anchor point and returns
|
|
|
-// the transformed image.
|
|
|
+// Fill creates an image with the specified dimensions and fills it with the scaled source image.
|
|
|
+// To achieve the correct aspect ratio without stretching, the source image will be cropped.
|
|
|
//
|
|
|
// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
|
|
|
// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
|
|
@@ -295,6 +294,10 @@ func Fill(img image.Image, width, height int, anchor Anchor, filter ResampleFilt
|
|
|
return resizeAndCrop(img, minW, minH, anchor, filter)
|
|
|
}
|
|
|
|
|
|
+// cropAndResize crops the image to the smallest possible size that has the required aspect ratio using
|
|
|
+// the given anchor point, then scales it to the specified dimensions and returns the transformed image.
|
|
|
+//
|
|
|
+// This is generally faster than resizing first, but may result in inaccuracies when used on small source images.
|
|
|
func cropAndResize(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA {
|
|
|
dstW, dstH := width, height
|
|
|
|
|
@@ -316,6 +319,9 @@ func cropAndResize(img image.Image, width, height int, anchor Anchor, filter Res
|
|
|
return Resize(tmp, dstW, dstH, filter)
|
|
|
}
|
|
|
|
|
|
+// resizeAndCrop resizes the image to the smallest possible size that will cover the specified dimensions,
|
|
|
+// crops the resized image to the specified dimensions using the given anchor point and returns
|
|
|
+// the transformed image.
|
|
|
func resizeAndCrop(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA {
|
|
|
dstW, dstH := width, height
|
|
|
|