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

cropper.getData() with rounded:true may lead to 1px more #343

Closed
sunderls opened this issue Apr 18, 2018 · 1 comment · Fixed by #344
Closed

cropper.getData() with rounded:true may lead to 1px more #343

sunderls opened this issue Apr 18, 2018 · 1 comment · Fixed by #344

Comments

@sunderls
Copy link

sunderls commented Apr 18, 2018

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report 
[ ] Feature request
[ ] Documentation issue or request

Current behavior

cropper.getData() support rounded:Boolean as parameter, but in our CMS we got this edge case:

// cropper.getData()
{
    height: 308.5,
    width: 617,
    x:-4.690122392697848e-14
    y:125.50000000000001
}

// cropper.getData(true)
{
     height:309,
     width:617,
     x:-0,
     y:126
}

AS you can see, the bottom border got increased by 1px

// before
y + height = 434.0000000000001
// after
y + height = 435

This 1px exceeds the image, and cause problems because we handle image cropping in server, with only coordinates got from js.

Expected behavior

The problem is that getData rounds x, y, width, height together.
Rather than rounding off width and height, maybe bottom, right is a more appropriate approach.

Minimal reproduction of the problem with instructions

Sorry it is very edge case, but here is very simple mental reproduction code

{
    height: 100.5
    width: 100.5
    x: 100.5
    y: 100.5
}

if we round, it will result in

{
     height: 101
     width: 101
     x: 101
     y: 101
}

What is the motivation / use case for changing the behavior?

bugfix.

Environment


Cropper.js version: 1.3.5

Browser:
- [x] Chrome (desktop) version 65.0.3325.181
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Others:

@qbadev
Copy link

qbadev commented Dec 31, 2019

Unfortunatelly, when using with responsive image, and a cropper widget scaled down a bit, it miscalculates data when rounding is enabled. In example, crop height is 301.4000, but it gives 302 rounded. Such exported crop data is useless, as Cropper can't process it. When I try to set data on cropper init, it is reset to default, as Cropper knows, that 302 is oversized.
My init params are:
viewMode 1
movable false
zoomable false
rotatable false
scalable false
autoCropArea 1
restore false
ratio 9/16
Original image size 800x536
Resized responsive image 715x479

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 a pull request may close this issue.

2 participants