Croppr.js icon indicating copy to clipboard operation
Croppr.js copied to clipboard

Using Croppr on a scaled page

Open jeroenbell opened this issue 7 years ago • 8 comments

Hi,

I'm using Croppr to provide my users a basic cropping tool. The only issue I'm having is that the page where the Croppr element is on, is scaled based on the browser width (and to add complexity the element can be scaled aswell). This leads to incorrect selection values. Using returnMode: raw returns the correct values, but I'm unable to select the entire image. Here's an example using the demo, with the center <div> scaled down to 0.85:

screen shot 2018-09-17 at 10 28 36

I've tried setting the inversed scale in the onInitialize hook like so onInitialize: instance => instance.scaleBy(1.25) but it seems that this is reset as soon as you resize/move the selection window.

jeroenbell avatar Sep 17 '18 08:09 jeroenbell

Hi @jeroenbell, a fix for this bug has been made in the develop branch. It will be released on npm once it's been fully tested out.

In the meantime you can download the latest distribution files on the develop branch.

jamesssooi avatar Sep 17 '18 16:09 jamesssooi

Hi @jamesssooi, thanks for the quick reply! I'm using the develop branch and have done some minor testing and all seems to work well. Will report back if I find any bugs.

jeroenbell avatar Sep 18 '18 09:09 jeroenbell

The only thing I've found so far is that upon resizing the window after starting a Croppr instance, the box doesn't respect the boundaries. Not sure why because as far as I can see every time a move is called, it uses .getBoudingClientRect() on the containing element, which should always return the correct dom values?

jeroenbell avatar Sep 18 '18 10:09 jeroenbell

Ah, that's because Croppr calculates a global scale factor to apply to the redraw() method only once during initialization. We can recalculate it on every redraw (very tiny performance hit?), or expose a method to recalculate these values (cluttering the API). Personally leaning towards the former.

jamesssooi avatar Sep 18 '18 14:09 jamesssooi

Yes I figured that. I've tried a quick hack by recalculating the boundaries on every window resize but that didn't seem to have any effect. I hope I'll have time to dig into the code a little deeper today.

jeroenbell avatar Sep 19 '18 07:09 jeroenbell

Hi,

I'm using Croppr to provide my users a basic cropping tool. The only issue I'm having is that the page where the Croppr element is on, is scaled based on the browser width (and to add complexity the element can be scaled aswell). This leads to incorrect selection values. Using returnMode: raw returns the correct values, but I'm unable to select the entire image. Here's an example using the demo, with the center <div> scaled down to 0.85:

screen shot 2018-09-17 at 10 28 36

I've tried setting the inversed scale in the onInitialize hook like so onInitialize: instance => instance.scaleBy(1.25) but it seems that this is reset as soon as you resize/move the selection window.

I know this is completely off topic, but could you please tell me what web browser you are using? I just love the look of it and would like to try it as well.

Chrisstar56 avatar Jan 03 '19 22:01 Chrisstar56

I know this is completely off topic, but could you please tell me what web browser you are using? I just love the look of it and would like to try it as well.

It's just Google Chrome. Not sure if it's rolled out to the stable version already, I'm using the developer build (version 73). If you don't have the new interface yet, you can try to enable it following the steps below: https://www.theverge.com/2018/7/26/17616112/how-to-chrome-material-design-refresh

jeroenbell avatar Jan 16 '19 15:01 jeroenbell

Any news on a release with this fix? Is this project still alive?

axelfontaine avatar Sep 13 '20 13:09 axelfontaine