Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#95 First shot for implementing Focal Point Cropping #96

Merged
merged 8 commits into from
Aug 2, 2018
Merged

#95 First shot for implementing Focal Point Cropping #96

merged 8 commits into from
Aug 2, 2018

Conversation

duergner
Copy link
Contributor

There are still tests missing and the way it has been implemented required changing all other filters to inject the basic Skipper FilterContext. This should most probably be refactored.

refs #95

There are still tests missing and the way it has been implemented required changing all other filters to inject the basic Skipper FilterContext. This should most probably be refactored.
@danpersa
Copy link
Collaborator

danpersa commented Jul 27, 2018

Please modify this filter as well to support this new feature. The free transform should support all of the new features we add. After doing this, you might decide not to create a separate filter anymore. This is also because as of now, the skrop routes don't contain dynamic things (like the x and y in your case). We created this new filter exactly to support dynamic parameters.

@duergner
Copy link
Contributor Author

Yeah thought about this as well. The downside I see with this filter is that it required to use a query param instead of path variables.

return CropByFocalPointName
}

func (f *cropByFocalPoint) CreateOptions(imageContext *ImageFilterContext, filterContext filters.FilterContext) (*bimg.Options, error) {
Copy link
Collaborator

@danpersa danpersa Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter context should not be passed here. Instead please extend this method to add the required information from the FilterContext to the ImageFilterContext

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danpersa I haven't found an easy way to expose all PathParams without actually knowing which are present.

But yes I agree about refactoring this.

@codecov-io
Copy link

codecov-io commented Jul 27, 2018

Codecov Report

Merging #96 into master will decrease coverage by 0.63%.
The diff coverage is 69.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #96      +/-   ##
=========================================
- Coverage   76.33%   75.7%   -0.64%     
=========================================
  Files          18      19       +1     
  Lines         786     856      +70     
=========================================
+ Hits          600     648      +48     
- Misses        137     154      +17     
- Partials       49      54       +5
Impacted Files Coverage Δ
filters/transformFromQueryParams.go 54.23% <0%> (-6.15%) ⬇️
filters/imagefilter.go 61.29% <100%> (+0.63%) ⬆️
filters/cropbyfocalpoint.go 74.19% <74.19%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e38864e...fef5e86. Read the comment docs.

focalPointX := ctx.PathParam("focalPointX");
focalPointY := ctx.PathParam("focalPointY");

if len(focalPointX) > 0 && len(focalPointY) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add the PathParams to the parameters, I would rather add all of the path params to the ImageFilterContext, something like this:

&ImageFilterContext{
 		Image:      image,
.....
                PathParams: pathParams
}

The reason is that with your approach, every time a new filter adds a new parameter we need to modify this method, which breaks the Open Closed Principle. As soon as the path parameters are part of the ImageFilterContext, each of the filters can access them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danpersa the problem is that Skipper currently does not allow to get all PathParams. You need to access them by name.

I can move them out of the parameters but unless there is a change in Skipper I don't see a way to add all PathParams without knowing which exist.

@danpersa
Copy link
Collaborator

Please don't forget to add tests (the build will fail otherwise) and update the README (there is a section there where we mention all of the filters)

@duergner
Copy link
Contributor Author

duergner commented Aug 2, 2018

@danpersa can you have another look. I added both tests for the new filter as well as an entry to the README file.

"github.com/zalando/skipper/filters"
"gopkg.in/h2non/bimg.v1"
"strconv"
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: I am not sure if gofmt is working correctly here. The ) should be at start of the line

}

func (f *cropByFocalPoint) CreateOptions(imageContext *ImageFilterContext) (*bimg.Options, error) {
log.Debug("Create options for crop by focal point ", f)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the debug line before merge.

}

func TestCropByFocalPoint_CreateOptions(t *testing.T) {
c := cropByFocalPoint{targetX: 0.5, targetY: 0.5, aspectRatio: 1.5}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably these repeating tests could be moved to a TableDriven tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given my very limited Go experience I wouldn't disagree if you suggest that.

I'll have a look on how to do this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. I am new too, but would love to be of help on this :)

@addityasingh
Copy link

@duergner I have added minor comments. Please check if they make sense

@duergner
Copy link
Contributor Author

duergner commented Aug 2, 2018

@addityasingh I did the two small fixes. Will have a look into the restructure to TableDriven tests.

return &bimg.Options{}, nil
}

// TODO do focal point crop
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duergner can you please open a ticket for this part, so that we don't forget about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danpersa done: #99

@danpersa
Copy link
Collaborator

danpersa commented Aug 2, 2018

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants