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

Automatic cropping doesn't always respect scale=down #12

Closed
lilith opened this issue Sep 24, 2012 · 6 comments
Closed

Automatic cropping doesn't always respect scale=down #12

lilith opened this issue Sep 24, 2012 · 6 comments
Assignees
Labels
Milestone

Comments

@lilith
Copy link
Member

lilith commented Sep 24, 2012

Bug in ImageBuilder.cs LayoutImage method:

Automatic cropping can bypass the scale=down checks in certain scenarios, such as when the requested and original aspect ratio differ significantly, and the uncropped (but resized) image would normally not cause upscaling.

Solving this without breaking things will require unit tests.

@lilith
Copy link
Member Author

lilith commented May 20, 2013

When &scale=down, upscaling should never occur. Instead, the image should only be cropped sufficiently to meet the size restrictions, not to meet the aspect ratio.

Example: Source image of 300x400

  • Querystring ?width=400&height=300&mode=crop&scale=down
  • Current result: 400x300 cropped, upscaled image
  • Correct result: 300x300 cropped, unresized image.

  • Querystring ?width=400&height=300&mode=crop&scale=canvas
  • Current result: 400x300 cropped, upscaled image
  • Correct result: 400x300 partially cropped, unresized image, padded to fit remainder.

  • Querystring ?width=400&height=300&mode=crop&scale=both
  • Current result: 400x300 cropped, upscaled image
  • Correct result: 400x300 cropped, upscaled image

@lilith
Copy link
Member Author

lilith commented May 29, 2013

Clarification for example 2, result 2: image should be cropped to 300x300, then padded with transparency to be 400x300.

@ghost ghost assigned JaredReisinger Nov 27, 2013
JaredReisinger added a commit that referenced this issue Dec 6, 2013
Fix logic bug in testing script so that all errors are reported, and "passed" only shows with no errors.
@JaredReisinger
Copy link
Contributor

I've added some DiagnosticJson regression tests for the above 3 cases, but I had to guess at the right numbers for the desired behavior. The current (master) code results in the following (the actual page has colors, which makes this easier to see):

autocrop scale down BAD (current):  passed
autocrop scale down GOOD (desired): failed : expected "300", got "400" for "result.finalRect.width".
autocrop scale down GOOD (desired): failed : expected "50", got "88" for "result.imageSourcePoly.y".
autocrop scale down GOOD (desired): failed : expected "300", got "225" for "result.imageSourcePoly.height".
autocrop scale down GOOD (desired): failed : expected "300", got "400" for "result.imageDestPoly.width".
autocrop scale down GOOD (desired): failed : expected "300", got "400" for "result.imageDestAreaPoly.width".

autocrop scale canvas BAD (current):  passed
autocrop scale canvas GOOD (desired): failed : expected "50", got "88" for "result.imageSourcePoly.y".
autocrop scale canvas GOOD (desired): failed : expected "300", got "225" for "result.imageSourcePoly.height".
autocrop scale canvas GOOD (desired): failed : expected "50", got "0" for "result.imageDestPoly.x".
autocrop scale canvas GOOD (desired): failed : expected "300", got "400" for "result.imageDestPoly.width".

autocrop scale both BAD (current):  passed
autocrop scale both GOOD (desired):  passed

manual/auto crop:  passed

Note that the BAD behavior is current passing, and the GOOD behavior is failing. (The third case @nathanaeljones listed had the current and correct values the same; I don't know if the current behavior is actually correct, or if there is a slight internal difference we should be looking for.) The fourth case ("manual/auto crop") comes from the comment in the pull request (issue #37), which would appear to already be passing.

@nathanaeljones, if you have a further set of commands/expectations in mind, I can add those as well; otherwise, I'll have to explore a bit to see what commands look like they might interact with autocrop and what values are interesting.

@lilith
Copy link
Member Author

lilith commented Dec 6, 2013

The current behavior is correct when scale=both is specified - the bug is for scale=down and scale=canvas being ignored.

@JaredReisinger
Copy link
Contributor

Cool. I can flatten/merge the third regression case down to the One True Correct behavior.

Would you like me to go ahead and merge the pull request, review and test it, and commit/push if it looks good?

@lilith
Copy link
Member Author

lilith commented Dec 7, 2013

Yes, let's go ahead and merge it.

JaredReisinger added a commit that referenced this issue Dec 11, 2013
JaredReisinger added a commit that referenced this issue Dec 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants