mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-18 08:15:14 +02:00
normalize rotate values
A -90 or 630 degree rotation is the same as 270.
This commit is contained in:
parent
76c8498abe
commit
07c54b46e3
2 changed files with 5 additions and 1 deletions
|
|
@ -208,7 +208,8 @@ func transformImage(m image.Image, opt Options) image.Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate
|
// rotate
|
||||||
switch opt.Rotate {
|
rotate := float64(opt.Rotate) - math.Floor(float64(opt.Rotate)/360)*360
|
||||||
|
switch rotate {
|
||||||
case 90:
|
case 90:
|
||||||
m = imaging.Rotate90(m)
|
m = imaging.Rotate90(m)
|
||||||
case 180:
|
case 180:
|
||||||
|
|
|
||||||
|
|
@ -165,9 +165,12 @@ func TestTransformImage(t *testing.T) {
|
||||||
|
|
||||||
// rotations
|
// rotations
|
||||||
{ref, Options{Rotate: 45}, ref}, // invalid rotation is a noop
|
{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: 90}, newImage(2, 2, green, yellow, red, blue)},
|
||||||
{ref, Options{Rotate: 180}, newImage(2, 2, yellow, blue, green, red)},
|
{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: 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
|
// flips
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue