aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/image_test.go
diff options
context:
space:
mode:
authorJohn Elliott <[email protected]>2022-02-22 16:50:23 +0000
committerBjørn Erik Pedersen <[email protected]>2022-02-23 10:01:50 +0100
commit7732da9f93503c1a723d6ac5bb77da206cb0fa0e (patch)
treea205fe894c5413a7dcaa6c6ad8ce64c93e61f874 /resources/image_test.go
parentaebde49b884c3b5ef73d8e1a01fca8a1354ac5b9 (diff)
downloadhugo-7732da9f93503c1a723d6ac5bb77da206cb0fa0e.tar.gz
hugo-7732da9f93503c1a723d6ac5bb77da206cb0fa0e.zip
Allow images to be cropped without being resized
Introduces the Crop method for image processing which implements gift.CropToSize. Also allows a smartCrop without resizing, and updates the documentation. Fixes #9499
Diffstat (limited to 'resources/image_test.go')
-rw-r--r--resources/image_test.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/resources/image_test.go b/resources/image_test.go
index ad8c42bd7..e85fe9b9a 100644
--- a/resources/image_test.go
+++ b/resources/image_test.go
@@ -137,6 +137,22 @@ func TestImageTransformBasic(t *testing.T) {
filledAgain, err := image.Fill("200x100 bottomLeft")
c.Assert(err, qt.IsNil)
c.Assert(filled, eq, filledAgain)
+
+ cropped, err := image.Crop("300x300 topRight")
+ c.Assert(err, qt.IsNil)
+ c.Assert(cropped.RelPermalink(), qt.Equals, "/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_300x300_crop_q68_linear_topright.jpg")
+ assertWidthHeight(cropped, 300, 300)
+
+ smartcropped, err := image.Crop("200x200 smart")
+ c.Assert(err, qt.IsNil)
+ c.Assert(smartcropped.RelPermalink(), qt.Equals, fmt.Sprintf("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x200_crop_q68_linear_smart%d.jpg", 1))
+ assertWidthHeight(smartcropped, 200, 200)
+
+ // Check cache
+ croppedAgain, err := image.Crop("300x300 topRight")
+ c.Assert(err, qt.IsNil)
+ c.Assert(cropped, eq, croppedAgain)
+
}
func TestImageTransformFormat(t *testing.T) {