diff --git a/data.go b/data.go index 118040f..59fed29 100644 --- a/data.go +++ b/data.go @@ -99,7 +99,7 @@ func (o Options) String() string { opts = append(opts, optFit) } if o.Rotate != 0 { - opts = append(opts, fmt.Sprintf("%s%d", string(optRotatePrefix), o.Rotate)) + opts = append(opts, fmt.Sprintf("%s%d", optRotatePrefix, o.Rotate)) } if o.FlipVertical { opts = append(opts, optFlipVertical) @@ -108,10 +108,10 @@ func (o Options) String() string { opts = append(opts, optFlipHorizontal) } if o.Quality != 0 { - opts = append(opts, fmt.Sprintf("%s%d", string(optQualityPrefix), o.Quality)) + opts = append(opts, fmt.Sprintf("%s%d", optQualityPrefix, o.Quality)) } if o.Signature != "" { - opts = append(opts, fmt.Sprintf("%s%s", string(optSignaturePrefix), o.Signature)) + opts = append(opts, fmt.Sprintf("%s%s", optSignaturePrefix, o.Signature)) } if o.ScaleUp { opts = append(opts, optScaleUp) @@ -120,16 +120,16 @@ func (o Options) String() string { opts = append(opts, o.Format) } if o.CropX != 0 { - opts = append(opts, fmt.Sprintf("%s%v", string(optCropX), o.CropX)) + opts = append(opts, fmt.Sprintf("%s%v", optCropX, o.CropX)) } if o.CropY != 0 { - opts = append(opts, fmt.Sprintf("%s%v", string(optCropY), o.CropY)) + opts = append(opts, fmt.Sprintf("%s%v", optCropY, o.CropY)) } if o.CropWidth != 0 { - opts = append(opts, fmt.Sprintf("%s%v", string(optCropWidth), o.CropWidth)) + opts = append(opts, fmt.Sprintf("%s%v", optCropWidth, o.CropWidth)) } if o.CropHeight != 0 { - opts = append(opts, fmt.Sprintf("%s%v", string(optCropHeight), o.CropHeight)) + opts = append(opts, fmt.Sprintf("%s%v", optCropHeight, o.CropHeight)) } if o.SmartCrop { opts = append(opts, optSmartCrop) diff --git a/data_test.go b/data_test.go index 6e4cda9..c73a9f8 100644 --- a/data_test.go +++ b/data_test.go @@ -32,20 +32,20 @@ func TestOptions_String(t *testing.T) { "0x0", }, { - Options{1, 2, true, 90, true, true, 80, "", false, "", 0, 0, 0, 0, false}, + Options{Width: 1, Height: 2, Fit: true, Rotate: 90, FlipVertical: true, FlipHorizontal: true, Quality: 80}, "1x2,fh,fit,fv,q80,r90", }, { - Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", false, "png", 0, 0, 0, 0, false}, + Options{Width: 0.15, Height: 1.3, Rotate: 45, Quality: 95, Signature: "c0ffee", Format: "png"}, "0.15x1.3,png,q95,r45,sc0ffee", }, { - Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", false, "", 100, 200, 0, 0, false}, - "0.15x1.3,cx100,cy200,q95,r45,sc0ffee", + Options{Width: 0.15, Height: 1.3, CropX: 100, CropY: 200}, + "0.15x1.3,cx100,cy200", }, { - Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", true, "png", 100, 200, 300, 400, true}, - "0.15x1.3,ch400,cw300,cx100,cy200,png,q95,r45,sc,sc0ffee,scaleUp", + Options{ScaleUp: true, CropX: 100, CropY: 200, CropWidth: 300, CropHeight: 400, SmartCrop: true}, + "0x0,ch400,cw300,cx100,cy200,sc,scaleUp", }, } @@ -95,19 +95,9 @@ func TestParseOptions(t *testing.T) { {"FOO,1,BAR,r90,BAZ", Options{Width: 1, Height: 1, Rotate: 90}}, // flags, in different orders - {"q70,1x2,fit,r90,fv,fh,sc0ffee,png", Options{1, 2, true, 90, true, true, 70, "c0ffee", false, "png", 0, 0, 0, 0, false}}, - {"r90,fh,sc0ffee,png,q90,1x2,fv,fit", Options{1, 2, true, 90, true, true, 90, "c0ffee", false, "png", 0, 0, 0, 0, false}}, - - // all flags, in different orders with crop - {"q70,cx100,cw300,1x2,fit,cy200,r90,fv,ch400,fh,sc0ffee,png,sc,scaleUp", Options{1, 2, true, 90, true, true, 70, "c0ffee", true, "png", 100, 200, 300, 400, true}}, - {"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, false}}, - - // all flags, in different orders with crop & different resizes - {"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, false}}, - {"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, false}}, - {"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, false}}, - {"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, false}}, - {"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, false}}, + {"q70,1x2,fit,r90,fv,fh,sc0ffee,png", Options{Width: 1, Height: 2, Fit: true, Rotate: 90, FlipVertical: true, FlipHorizontal: true, Quality: 70, Signature: "c0ffee", Format: "png"}}, + {"r90,fh,sc0ffee,png,q90,1x2,fv,fit", Options{Width: 1, Height: 2, Fit: true, Rotate: 90, FlipVertical: true, FlipHorizontal: true, Quality: 90, Signature: "c0ffee", Format: "png"}}, + {"cx100,cw300,1x2,cy200,ch400,sc,scaleUp", Options{Width: 1, Height: 2, ScaleUp: true, CropX: 100, CropY: 200, CropWidth: 300, CropHeight: 400, SmartCrop: true}}, } for _, tt := range tests {