Skip to content

Commit 07c54b4

Browse files
committed
normalize rotate values
A -90 or 630 degree rotation is the same as 270.
1 parent 76c8498 commit 07c54b4

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

transform.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ func transformImage(m image.Image, opt Options) image.Image {
208208
}
209209

210210
// rotate
211-
switch opt.Rotate {
211+
rotate := float64(opt.Rotate) - math.Floor(float64(opt.Rotate)/360)*360
212+
switch rotate {
212213
case 90:
213214
m = imaging.Rotate90(m)
214215
case 180:

transform_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,12 @@ func TestTransformImage(t *testing.T) {
165165

166166
// rotations
167167
{ref, Options{Rotate: 45}, ref}, // invalid rotation is a noop
168+
{ref, Options{Rotate: 360}, ref},
168169
{ref, Options{Rotate: 90}, newImage(2, 2, green, yellow, red, blue)},
169170
{ref, Options{Rotate: 180}, newImage(2, 2, yellow, blue, green, red)},
170171
{ref, Options{Rotate: 270}, newImage(2, 2, blue, red, yellow, green)},
172+
{ref, Options{Rotate: 630}, newImage(2, 2, blue, red, yellow, green)},
173+
{ref, Options{Rotate: -90}, newImage(2, 2, blue, red, yellow, green)},
171174

172175
// flips
173176
{

0 commit comments

Comments
 (0)