From 03d75816a082e87a7161bf45fb1a4e8ffa1c0424 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Wed, 6 Sep 2017 22:01:13 +0000 Subject: [PATCH] fix ordering of flip and rotation transformations Fixes #112 --- transform.go | 16 ++++++++-------- transform_test.go | 7 ++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/transform.go b/transform.go index cfa00bf..92e0d82 100644 --- a/transform.go +++ b/transform.go @@ -207,14 +207,6 @@ func transformImage(m image.Image, opt Options) image.Image { } } - // flip - if opt.FlipVertical { - m = imaging.FlipV(m) - } - if opt.FlipHorizontal { - m = imaging.FlipH(m) - } - // rotate switch opt.Rotate { case 90: @@ -225,5 +217,13 @@ func transformImage(m image.Image, opt Options) image.Image { m = imaging.Rotate270(m) } + // flip + if opt.FlipVertical { + m = imaging.FlipV(m) + } + if opt.FlipHorizontal { + m = imaging.FlipH(m) + } + return m } diff --git a/transform_test.go b/transform_test.go index 7fc0e5c..2897bbc 100644 --- a/transform_test.go +++ b/transform_test.go @@ -185,6 +185,11 @@ func TestTransformImage(t *testing.T) { Options{FlipHorizontal: true, FlipVertical: true}, newImage(2, 2, yellow, blue, green, red), }, + { + ref, + Options{Rotate: 90, FlipHorizontal: true}, + newImage(2, 2, yellow, green, blue, red), + }, // resizing { // can't resize larger than original image @@ -247,7 +252,7 @@ func TestTransformImage(t *testing.T) { { newImage(4, 2, red, red, blue, blue, red, red, blue, blue), Options{Width: 2, Height: 1, Fit: true, FlipHorizontal: true, Rotate: 90}, - newImage(1, 2, red, blue), + newImage(1, 2, blue, red), }, // crop