question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot resize or move after onImageLoaded

See original GitHub issue

This is probably related to #280

Steps to reproduce:

Select image, preferable a portrait or landscape for best effect. Click a handle to resize OR click and drag in the middle to move the crop area.

Expected results Crop area is resized or moved

Actual results Nothing happens on FIRST interaction, but if I try again, I get the expected results.

DEMO

I’ve forked your example from the README here: https://codesandbox.io/s/react-image-crop-demo-3mtjy

What I wish to achieve: I want to have a default square crop area when react-image-crop loads.

I’ve set the initial crop aspect ratio to 1 just so I can reuse the state in onImageLoaded. Then the function looks like this:

onImageLoaded = image => {
    const { width, height } = image;

    let crop;

    if (width > height) {
      crop = {
        ...this.state.crop,
        width: height,
        height,
        x: width / 2 - height / 2,
        y: 0
      };
    } else {
      crop = {
        ...this.state.crop,
        width,
        height: width,
        x: 0,
        y: height / 2 - width / 2
      };
    }

    this.setState({ crop });
    return false;
  };

I seem to need to provide both width and height for this to work.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
designbyadriancommented, Aug 18, 2019

Hi there! That certainly isn’t the worst work-around I’ve seen! 😄 My issue is resolved.

1reaction
DominicTobiascommented, Aug 16, 2019

You can workaround the issue by adding unit: 'px' to your crop in onImageLoaded, though it should have defaulted to this (bug)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't resize with Move Tool - Adobe Support Community
Hi. To resize the entire Image, use the Image menu > Image size; To resize a layer ot selection, use Edit > Free...
Read more >
Windows 11:Can't move or resize windows/applications
I updated windows not too long ago and now my application windows don't want to move or resize. It's pretty annoying.
Read more >
react-image-crop - npm
A callback which happens when a user starts dragging or resizing. It is convenient to manipulate elements outside this component. onDragEnd?: (e ...
Read more >
Can't resize an ImageView from a dynamic declaration
But this is not : if I declare my imageView without using XML, it just won't resize, and also it won't move when...
Read more >
Image Resizing Problems in Microsoft Publisher - Sign In
Issue/Question. I have inserted an image into Publisher, but when I try to move or resize the image it displays strange graphical glitches ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found