mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-04-27 13:56:25 +02:00
add options to flip horizontally and vertically
This commit is contained in:
parent
d506fc6881
commit
a039c1bbca
4 changed files with 36 additions and 10 deletions
12
data/data.go
12
data/data.go
|
|
@ -35,6 +35,9 @@ type Options struct {
|
||||||
|
|
||||||
// Rotate image the specified degrees counter-clockwise. Valid values are 90, 180, 270.
|
// Rotate image the specified degrees counter-clockwise. Valid values are 90, 180, 270.
|
||||||
Rotate int
|
Rotate int
|
||||||
|
|
||||||
|
FlipVertical bool
|
||||||
|
FlipHorizontal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Options) String() string {
|
func (o Options) String() string {
|
||||||
|
|
@ -68,6 +71,15 @@ func ParseOptions(str string) *Options {
|
||||||
o.Fit = true
|
o.Fit = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if part == "fv" {
|
||||||
|
o.FlipVertical = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if part == "fh" {
|
||||||
|
o.FlipHorizontal = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if len(part) > 2 && strings.HasPrefix(part, "r=") {
|
if len(part) > 2 && strings.HasPrefix(part, "r=") {
|
||||||
o.Rotate, _ = strconv.Atoi(part[2:])
|
o.Rotate, _ = strconv.Atoi(part[2:])
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -84,27 +84,27 @@ func TestNewRequest(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"http://localhost/1x/http://example.com/",
|
"http://localhost/1x/http://example.com/",
|
||||||
"http://example.com/", &data.Options{1, 0, false}, false,
|
"http://example.com/", &data.Options{1, 0, false, 0, false, false}, false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"http://localhost/x1/http://example.com/",
|
"http://localhost/x1/http://example.com/",
|
||||||
"http://example.com/", &data.Options{0, 1, false}, false,
|
"http://example.com/", &data.Options{0, 1, false, 0, false, false}, false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"http://localhost/1x2/http://example.com/",
|
"http://localhost/1x2/http://example.com/",
|
||||||
"http://example.com/", &data.Options{1, 2, false}, false,
|
"http://example.com/", &data.Options{1, 2, false, 0, false, false}, false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"http://localhost/0.1x0.2/http://example.com/",
|
||||||
|
"http://example.com/", &data.Options{0.1, 0.2, false, 0, false, false}, false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"http://localhost/,fit/http://example.com/",
|
"http://localhost/,fit/http://example.com/",
|
||||||
"http://example.com/", &data.Options{0, 0, true}, false,
|
"http://example.com/", &data.Options{0, 0, true, 0, false, false}, false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"http://localhost/1x2,fit/http://example.com/",
|
"http://localhost/1x2,fit,r=90,fv,fh/http://example.com/",
|
||||||
"http://example.com/", &data.Options{1, 2, true}, false,
|
"http://example.com/", &data.Options{1, 2, true, 90, true, true}, false,
|
||||||
},
|
|
||||||
{
|
|
||||||
"http://localhost/0.1x0.2,fit/http://example.com/",
|
|
||||||
"http://example.com/", &data.Options{0.1, 0.2, true}, false,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ The `r={degrees}` option will rotate the image the specified number of degrees,
|
||||||
counter-clockwise. Valid degrees values are `90`, `180`, and `270`. Images
|
counter-clockwise. Valid degrees values are `90`, `180`, and `270`. Images
|
||||||
are rotated **after** being resized.
|
are rotated **after** being resized.
|
||||||
|
|
||||||
|
#### Flip ####
|
||||||
|
|
||||||
|
The `fv` option will flip the image vertically. The `fh` option will flip the
|
||||||
|
image horizontally. Images are flipped **after** being resized and rotated.
|
||||||
|
|
||||||
### Remote URL ###
|
### Remote URL ###
|
||||||
|
|
||||||
The URL of the original image to load is specified as the remainder of the
|
The URL of the original image to load is specified as the remainder of the
|
||||||
|
|
@ -92,6 +97,7 @@ x100 | 100px tall, proportional width | 
|
100 | 100px square, cropping as needed | 
|
||||||
150,fit | fit to be no more than 150 by 150 pixels | 
|
150,fit | fit to be no more than 150 by 150 pixels | 
|
||||||
100,r=90| 100px square, rotated 90 degrees | 
|
100,r=90| 100px square, rotated 90 degrees | 
|
||||||
|
100,fv,fh | 100px square, flipped horizontal and vertical | 
|
||||||
|
|
||||||
|
|
||||||
## License ##
|
## License ##
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,14 @@ func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// flip
|
||||||
|
if opt.FlipVertical {
|
||||||
|
m = imaging.FlipV(m)
|
||||||
|
}
|
||||||
|
if opt.FlipHorizontal {
|
||||||
|
m = imaging.FlipH(m)
|
||||||
|
}
|
||||||
|
|
||||||
// rotate
|
// rotate
|
||||||
switch opt.Rotate {
|
switch opt.Rotate {
|
||||||
case 90:
|
case 90:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue