From 06e9c87ea917bef8b1ad41ec2d1aca82d0510b11 Mon Sep 17 00:00:00 2001 From: qeesung <1245712564@qq.com> Date: Thu, 25 Oct 2018 22:51:07 +0800 Subject: [PATCH] add scale image example --- convert/resize_test.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/convert/resize_test.go b/convert/resize_test.go index 0c34ccd..59e178b 100644 --- a/convert/resize_test.go +++ b/convert/resize_test.go @@ -5,6 +5,7 @@ import ( "github.com/mattn/go-isatty" "github.com/stretchr/testify/assert" "io/ioutil" + "log" "os" "os/exec" "strings" @@ -15,7 +16,11 @@ import ( func TestGetTerminalScreenSize(t *testing.T) { assertions := assert.New(t) _, _, err := getTerminalScreenSize() - assertions.True(err != nil) + if !isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()) { + assertions.True(err != nil) + } else { + assertions.True(err == nil) + } } // TestOpenImageFile test open different type image file @@ -155,3 +160,23 @@ func TestScaleToFitTerminalSize(t *testing.T) { t.Fatalf("Process ran with err %v, want exit status 1", err) } } + + +// ExampleScaleImage is scale image example +func ExampleScaleImage() { + imageFilePath := "testdata/cat_2000x1500.jpg" + img, err := OpenImageFile(imageFilePath) + if err != nil { + log.Fatal("open image file "+imageFilePath + " failed") + } + + options := defaultOptions + options.Colored = false + options.ExpectedWidth = 200 + options.ExpectedHeight = 100 + + scaledImage := ScaleImage(img, &options) + sz := scaledImage.Bounds() + fmt.Print(sz.Max.X, sz.Max.Y) + // output: 200 100 +} \ No newline at end of file -- 2.45.2