1

I am making an image cropper, the cropper has to be of a fixed dimension, but those dimensions can be dynamically changed by the user.

Everytime the box updates, I run this code.

        let dimensions = {
          height: 300,
          width: 431
        }

        function makeSize()
        {
          console.log(cropper + ' ' + dimensions.height + " " + dimensions.width); // [object Object] 300 431
          cropper.setCropBoxData({

              height: dimensions.height,
              width: dimensions.width

          });
        }

I do this to make sure the dimensions remain the same. For some reason this doesn't work. However, if I change the setCropBoxData function to this

            cropper.setCropBoxData({

              height: 431,
              width: 300

            });

Everything works fine.

No errors in the console,nothing. I'm at a totall loss.

Rien Bijl
  • 43
  • 6

2 Answers2

2

After reassigning the variables they appeared for some reason as strings. I don't know why javascript didn't automagically type juggle to integers. After using parseInt() the problem was fixed.

Rien Bijl
  • 43
  • 6
0

I believe dimensions is not accessible to the inner function, you should pass it as a parameter. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let

BobtheMagicMoose
  • 2,246
  • 3
  • 19
  • 27
  • 1
    Unfortunately this isn't that easy, as seen in the code `console.log(cropper + ' ' + dimensions.height + " " + dimensions.width);`, I can actually access those variables. – Rien Bijl Jun 24 '19 at 14:02
  • Looks like your height and width are switched, would that be the issue? – BobtheMagicMoose Jun 24 '19 at 21:40