mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-04 09:12:39 +02:00
parent
d825852025
commit
a71584a63c
3 changed files with 10 additions and 3 deletions
9
data.go
9
data.go
|
|
@ -72,8 +72,6 @@ type Options struct {
|
||||||
ScaleUp bool
|
ScaleUp bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var emptyOptions = Options{}
|
|
||||||
|
|
||||||
func (o Options) String() string {
|
func (o Options) String() string {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
fmt.Fprintf(buf, "%v%s%v", o.Width, optSizeDelimiter, o.Height)
|
fmt.Fprintf(buf, "%v%s%v", o.Width, optSizeDelimiter, o.Height)
|
||||||
|
|
@ -101,6 +99,13 @@ func (o Options) String() string {
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transform returns whether o includes transformation options. Some fields
|
||||||
|
// are not transform related at all (like Signature), and others only apply in
|
||||||
|
// the presence of other fields (like Fit and Quality).
|
||||||
|
func (o Options) transform() bool {
|
||||||
|
return o.Width != 0 || o.Height != 0 || o.Rotate != 0 || o.FlipHorizontal || o.FlipVertical
|
||||||
|
}
|
||||||
|
|
||||||
// ParseOptions parses str as a list of comma separated transformation options.
|
// ParseOptions parses str as a list of comma separated transformation options.
|
||||||
// The following options can be specified in any order:
|
// The following options can be specified in any order:
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var emptyOptions = Options{}
|
||||||
|
|
||||||
func TestOptions_String(t *testing.T) {
|
func TestOptions_String(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Options Options
|
Options Options
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ var resampleFilter = imaging.Lanczos
|
||||||
// encoded image in one of the supported formats (gif, jpeg, or png). The
|
// encoded image in one of the supported formats (gif, jpeg, or png). The
|
||||||
// bytes of a similarly encoded image is returned.
|
// bytes of a similarly encoded image is returned.
|
||||||
func Transform(img []byte, opt Options) ([]byte, error) {
|
func Transform(img []byte, opt Options) ([]byte, error) {
|
||||||
if opt == emptyOptions {
|
if !opt.transform() {
|
||||||
// bail if no transformation was requested
|
// bail if no transformation was requested
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue