mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
reorder rectangular crop parameters
change to x, y, width, height to more closely align with how parameters are passed in the image package.
This commit is contained in:
parent
1b70c6afd0
commit
a33df59013
2 changed files with 26 additions and 26 deletions
34
data.go
34
data.go
|
@ -34,10 +34,10 @@ const (
|
|||
optSignaturePrefix = "s"
|
||||
optSizeDelimiter = "x"
|
||||
optScaleUp = "scaleUp"
|
||||
optCropWidth = "cw"
|
||||
optCropHeight = "ch"
|
||||
optCropX = "cx"
|
||||
optCropY = "cy"
|
||||
optCropWidth = "cw"
|
||||
optCropHeight = "ch"
|
||||
)
|
||||
|
||||
// URLError reports a malformed URL error.
|
||||
|
@ -81,10 +81,10 @@ type Options struct {
|
|||
Format string
|
||||
|
||||
// Crop rectangle params
|
||||
CropWidth int
|
||||
CropHeight int
|
||||
CropX int
|
||||
CropY int
|
||||
CropWidth int
|
||||
CropHeight int
|
||||
}
|
||||
|
||||
func (o Options) String() string {
|
||||
|
@ -113,18 +113,18 @@ func (o Options) String() string {
|
|||
if o.Format != "" {
|
||||
opts = append(opts, o.Format)
|
||||
}
|
||||
if o.CropWidth != 0 {
|
||||
opts = append(opts, fmt.Sprintf("%s%d", string(optCropWidth), o.CropWidth))
|
||||
}
|
||||
if o.CropHeight != 0 {
|
||||
opts = append(opts, fmt.Sprintf("%s%d", string(optCropHeight), o.CropHeight))
|
||||
}
|
||||
if o.CropX != 0 {
|
||||
opts = append(opts, fmt.Sprintf("%s%d", string(optCropX), o.CropX))
|
||||
}
|
||||
if o.CropY != 0 {
|
||||
opts = append(opts, fmt.Sprintf("%s%d", string(optCropY), o.CropY))
|
||||
}
|
||||
if o.CropWidth != 0 {
|
||||
opts = append(opts, fmt.Sprintf("%s%d", string(optCropWidth), o.CropWidth))
|
||||
}
|
||||
if o.CropHeight != 0 {
|
||||
opts = append(opts, fmt.Sprintf("%s%d", string(optCropHeight), o.CropHeight))
|
||||
}
|
||||
return strings.Join(opts, ",")
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ func (o Options) String() string {
|
|||
// the presence of other fields (like Fit). A non-empty Format value is
|
||||
// assumed to involve a transformation.
|
||||
func (o Options) transform() bool {
|
||||
return o.Width != 0 || o.Height != 0 || o.Rotate != 0 || o.FlipHorizontal || o.FlipVertical || o.Quality != 0 || o.Format != "" || (o.CropHeight != 0 && o.CropWidth != 0)
|
||||
return o.Width != 0 || o.Height != 0 || o.Rotate != 0 || o.FlipHorizontal || o.FlipVertical || o.Quality != 0 || o.Format != "" || (o.CropWidth != 0 && o.CropHeight != 0)
|
||||
}
|
||||
|
||||
// ParseOptions parses str as a list of comma separated transformation options.
|
||||
|
@ -252,18 +252,18 @@ func ParseOptions(str string) Options {
|
|||
options.Quality, _ = strconv.Atoi(value)
|
||||
case strings.HasPrefix(opt, optSignaturePrefix):
|
||||
options.Signature = strings.TrimPrefix(opt, optSignaturePrefix)
|
||||
case strings.HasPrefix(opt, optCropHeight):
|
||||
value := strings.TrimPrefix(opt, optCropHeight)
|
||||
options.CropHeight, _ = strconv.Atoi(value)
|
||||
case strings.HasPrefix(opt, optCropWidth):
|
||||
value := strings.TrimPrefix(opt, optCropWidth)
|
||||
options.CropWidth, _ = strconv.Atoi(value)
|
||||
case strings.HasPrefix(opt, optCropX):
|
||||
value := strings.TrimPrefix(opt, optCropX)
|
||||
options.CropX, _ = strconv.Atoi(value)
|
||||
case strings.HasPrefix(opt, optCropY):
|
||||
value := strings.TrimPrefix(opt, optCropY)
|
||||
options.CropY, _ = strconv.Atoi(value)
|
||||
case strings.HasPrefix(opt, optCropWidth):
|
||||
value := strings.TrimPrefix(opt, optCropWidth)
|
||||
options.CropWidth, _ = strconv.Atoi(value)
|
||||
case strings.HasPrefix(opt, optCropHeight):
|
||||
value := strings.TrimPrefix(opt, optCropHeight)
|
||||
options.CropHeight, _ = strconv.Atoi(value)
|
||||
case strings.Contains(opt, optSizeDelimiter):
|
||||
size := strings.SplitN(opt, optSizeDelimiter, 2)
|
||||
if w := size[0]; w != "" {
|
||||
|
|
18
data_test.go
18
data_test.go
|
@ -40,11 +40,11 @@ func TestOptions_String(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", false, "", 100, 200, 0, 0},
|
||||
"0.15x1.3,r45,q95,sc0ffee,cw100,ch200",
|
||||
"0.15x1.3,r45,q95,sc0ffee,cx100,cy200",
|
||||
},
|
||||
{
|
||||
Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", false, "png", 100, 200, 300, 400},
|
||||
"0.15x1.3,r45,q95,sc0ffee,png,cw100,ch200,cx300,cy400",
|
||||
"0.15x1.3,r45,q95,sc0ffee,png,cx100,cy200,cw300,ch400",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -98,15 +98,15 @@ func TestParseOptions(t *testing.T) {
|
|||
{"r90,fh,sc0ffee,png,q90,1x2,fv,fit", Options{1, 2, true, 90, true, true, 90, "c0ffee", false, "png", 0, 0, 0, 0}},
|
||||
|
||||
// all flags, in different orders with crop
|
||||
{"q70,cw100,cx300,1x2,fit,ch200,r90,fv,cy400,fh,sc0ffee,png", Options{1, 2, true, 90, true, true, 70, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
{"cy400,r90,cx300,fh,sc0ffee,png,cw100,q90,ch200,1x2,fv,fit", Options{1, 2, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
{"q70,cx100,cw300,1x2,fit,cy200,r90,fv,ch400,fh,sc0ffee,png", Options{1, 2, true, 90, true, true, 70, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
{"ch400,r90,cw300,fh,sc0ffee,png,cx100,q90,cy200,1x2,fv,fit", Options{1, 2, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
|
||||
// all flags, in different orders with crop & different resizes
|
||||
{"q70,cw100,cx300,x2,fit,ch200,r90,fv,cy400,fh,sc0ffee,png", Options{0, 2, true, 90, true, true, 70, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
{"cy400,r90,cx300,fh,sc0ffee,png,cw100,q90,ch200,1x,fv,fit", Options{1, 0, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
{"cy400,r90,cx300,fh,sc0ffee,png,cw100,q90,ch200,cx,fv,fit", Options{0, 0, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 0, 400}},
|
||||
{"cy400,r90,cx300,fh,sc0ffee,png,cw100,q90,ch200,cx,fv,fit,123x321", Options{123, 321, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 0, 400}},
|
||||
{"123x321,cy400,r90,cx300,fh,sc0ffee,png,cw100,q90,ch200,cx,fv,fit", Options{123, 321, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 0, 400}},
|
||||
{"q70,cx100,cw300,x2,fit,cy200,r90,fv,ch400,fh,sc0ffee,png", Options{0, 2, true, 90, true, true, 70, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
{"ch400,r90,cw300,fh,sc0ffee,png,cx100,q90,cy200,1x,fv,fit", Options{1, 0, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 300, 400}},
|
||||
{"ch400,r90,cw300,fh,sc0ffee,png,cx100,q90,cy200,cw,fv,fit", Options{0, 0, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 0, 400}},
|
||||
{"ch400,r90,cw300,fh,sc0ffee,png,cx100,q90,cy200,cw,fv,fit,123x321", Options{123, 321, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 0, 400}},
|
||||
{"123x321,ch400,r90,cw300,fh,sc0ffee,png,cx100,q90,cy200,cw,fv,fit", Options{123, 321, true, 90, true, true, 90, "c0ffee", false, "png", 100, 200, 0, 400}},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
Loading…
Reference in a new issue