Skip to content

Commit

Permalink
po.Resize => po.ResizingType
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthSim committed Oct 11, 2019
1 parent a798530 commit 0d5d2f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func calcScale(width, height int, po *processingOptions, imgtype imageType) floa
wshrink := srcW / dstW
hshrink := srcH / dstH

rt := po.Resize
rt := po.ResizingType

if rt == resizeAuto {
srcD := width - height
Expand Down Expand Up @@ -222,7 +222,7 @@ func prepareWatermark(wm *vipsImage, wmData *imageData, opts *watermarkOptions,
}

po := newProcessingOptions()
po.Resize = resizeFit
po.ResizingType = resizeFit
po.Dpr = 1
po.Enlarge = true
po.Format = wmData.Type
Expand Down Expand Up @@ -636,12 +636,12 @@ func processImage(ctx context.Context) ([]byte, context.CancelFunc, error) {
}
}

if po.Resize == resizeCrop {
if po.ResizingType == resizeCrop {
logWarning("`crop` resizing type is deprecated and will be removed in future versions. Use `crop` processing option instead")

po.Crop.Width, po.Crop.Height = po.Width, po.Height

po.Resize = resizeFit
po.ResizingType = resizeFit
po.Width, po.Height = 0, 0
}

Expand Down
56 changes: 28 additions & 28 deletions processing_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ type watermarkOptions struct {
}

type processingOptions struct {
Resize resizeType
Width int
Height int
Dpr float64
Gravity gravityOptions
Enlarge bool
Extend bool
Crop cropOptions
Format imageType
Quality int
Flatten bool
Background rgbColor
Blur float32
Sharpen float32
ResizingType resizeType
Width int
Height int
Dpr float64
Gravity gravityOptions
Enlarge bool
Extend bool
Crop cropOptions
Format imageType
Quality int
Flatten bool
Background rgbColor
Blur float32
Sharpen float32

CacheBuster string

Expand Down Expand Up @@ -187,18 +187,18 @@ var (
func newProcessingOptions() *processingOptions {
newProcessingOptionsOnce.Do(func() {
_newProcessingOptions = processingOptions{
Resize: resizeFit,
Width: 0,
Height: 0,
Gravity: gravityOptions{Type: gravityCenter},
Enlarge: false,
Quality: conf.Quality,
Format: imageTypeUnknown,
Background: rgbColor{255, 255, 255},
Blur: 0,
Sharpen: 0,
Dpr: 1,
Watermark: watermarkOptions{Opacity: 1, Replicate: false, Gravity: gravityCenter},
ResizingType: resizeFit,
Width: 0,
Height: 0,
Gravity: gravityOptions{Type: gravityCenter},
Enlarge: false,
Quality: conf.Quality,
Format: imageTypeUnknown,
Background: rgbColor{255, 255, 255},
Blur: 0,
Sharpen: 0,
Dpr: 1,
Watermark: watermarkOptions{Opacity: 1, Replicate: false, Gravity: gravityCenter},
}
})

Expand Down Expand Up @@ -450,7 +450,7 @@ func applyResizingTypeOption(po *processingOptions, args []string) error {
}

if r, ok := resizeTypes[args[0]]; ok {
po.Resize = r
po.ResizingType = r
} else {
return fmt.Errorf("Invalid resize type: %s", args[0])
}
Expand Down Expand Up @@ -884,7 +884,7 @@ func parsePathBasic(parts []string, headers *processingHeaders) (string, *proces
return "", po, err
}

po.Resize = resizeTypes[parts[0]]
po.ResizingType = resizeTypes[parts[0]]

if err = applyWidthOption(po, parts[1:2]); err != nil {
return "", po, err
Expand Down
10 changes: 5 additions & 5 deletions processing_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathBasic() {
require.Nil(s.T(), err)

po := getProcessingOptions(ctx)
assert.Equal(s.T(), resizeFill, po.Resize)
assert.Equal(s.T(), resizeFill, po.ResizingType)
assert.Equal(s.T(), 100, po.Width)
assert.Equal(s.T(), 200, po.Height)
assert.Equal(s.T(), gravityNorthEast, po.Gravity.Type)
Expand All @@ -138,7 +138,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedResize() {
require.Nil(s.T(), err)

po := getProcessingOptions(ctx)
assert.Equal(s.T(), resizeFill, po.Resize)
assert.Equal(s.T(), resizeFill, po.ResizingType)
assert.Equal(s.T(), 100, po.Width)
assert.Equal(s.T(), 200, po.Height)
assert.True(s.T(), po.Enlarge)
Expand All @@ -151,7 +151,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedResizingType() {
require.Nil(s.T(), err)

po := getProcessingOptions(ctx)
assert.Equal(s.T(), resizeFill, po.Resize)
assert.Equal(s.T(), resizeFill, po.ResizingType)
}

func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedSize() {
Expand Down Expand Up @@ -322,7 +322,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathAdvancedPreset() {
require.Nil(s.T(), err)

po := getProcessingOptions(ctx)
assert.Equal(s.T(), resizeFill, po.Resize)
assert.Equal(s.T(), resizeFill, po.ResizingType)
assert.Equal(s.T(), float32(0.2), po.Blur)
assert.Equal(s.T(), 50, po.Quality)
}
Expand All @@ -340,7 +340,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathPresetDefault() {
require.Nil(s.T(), err)

po := getProcessingOptions(ctx)
assert.Equal(s.T(), resizeFill, po.Resize)
assert.Equal(s.T(), resizeFill, po.ResizingType)
assert.Equal(s.T(), float32(0.2), po.Blur)
assert.Equal(s.T(), 70, po.Quality)
}
Expand Down

0 comments on commit 0d5d2f5

Please sign in to comment.