0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

normalize rotate values

A -90 or 630 degree rotation is the same as 270.
This commit is contained in:
Will Norris 2017-09-06 21:06:52 +00:00
parent 76c8498abe
commit 07c54b46e3
2 changed files with 5 additions and 1 deletions

View file

@ -208,7 +208,8 @@ func transformImage(m image.Image, opt Options) image.Image {
}
// rotate
switch opt.Rotate {
rotate := float64(opt.Rotate) - math.Floor(float64(opt.Rotate)/360)*360
switch rotate {
case 90:
m = imaging.Rotate90(m)
case 180:

View file

@ -165,9 +165,12 @@ func TestTransformImage(t *testing.T) {
// rotations
{ref, Options{Rotate: 45}, ref}, // invalid rotation is a noop
{ref, Options{Rotate: 360}, ref},
{ref, Options{Rotate: 90}, newImage(2, 2, green, yellow, red, blue)},
{ref, Options{Rotate: 180}, newImage(2, 2, yellow, blue, green, red)},
{ref, Options{Rotate: 270}, newImage(2, 2, blue, red, yellow, green)},
{ref, Options{Rotate: 630}, newImage(2, 2, blue, red, yellow, green)},
{ref, Options{Rotate: -90}, newImage(2, 2, blue, red, yellow, green)},
// flips
{