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.

Strange overlay issue

See original GitHub issue

In my app I’m getting an issue when selecting large images, where the crop doesn’t match the highlight:

screen shot 2016-02-25 at 14 33 47

I have set:

.ReactCrop--image {
  max-width: 100%;
}

…and have tried all sorts of combinations for crop params. Also, how do I go about selecting the default selected crop to be either 100% of width (if portrait) or 100% of height (if landscape) and keeping the aspect ratio 1/1 (square)?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
DPr00fcommented, Feb 25, 2016

The library doesn’t have any code for upload. Although you could pick up the base64 and send it for S3. Take this as an example

  onCropComplete(crop) {
    this.previewImage(crop).then((canvasUrl) => {
        ApiActions.uploadBase64(canvasUrl, this.getDraftUploadFileName(true));
    });
  }

previewImage(crop) {
    return new Promise((resolve, reject) => {
      var img = new Image();
      img.setAttribute('crossOrigin', 'anonymous');
      img.onload = () => {
        var imageWidth = crop.originalWidth;
        var imageHeight = crop.originalHeight;

        var cropX = (crop.x / 100) * imageWidth;
        var cropY = (crop.y / 100) * imageHeight;

        var cropWidth = (crop.width / 100) * imageWidth;
        var cropHeight = (crop.height / 100) * imageHeight;

        var destWidth = cropWidth;
        var destHeight = cropHeight;
        var canvasWidth = cropWidth;
        var canvasHeight = cropHeight;

        if(crop.maxWidth || crop.maxHeight) {
          var scaledCrop = this.scale({
              width: cropWidth,
              height: cropHeight,
              maxWidth: crop.maxWidth * 2,
              maxHeight: crop.maxHeight * 2
          });

          // Scale the image based on the crop scale.
          var scaledImage = this.scale({
              scale: scaledCrop.scale,
              width: imageWidth,
              height: imageHeight
          });
          destWidth = scaledCrop.width;
          destHeight = scaledCrop.height;
          canvasWidth = scaledCrop.width;
          canvasHeight = scaledCrop.height;
        }

        var canvas = document.createElement('canvas');
        canvas.width = canvasWidth;
        canvas.height = canvasHeight;
        var ctx = canvas.getContext('2d');
        ctx.drawImage(img, cropX, cropY, cropWidth, cropHeight, 0, 0, destWidth, destHeight);
        var canvasUrl = canvas.toDataURL('image/png');
        resolve(canvasUrl);
      }
      img.src = this.state.originalImageUrl;
    });
  }

scale(options) {
    var scale = options.scale || Math.min(options.maxWidth/options.width, options.maxHeight/options.height);

    scale = Math.min(scale, 100);

    return {
      scale: scale,
      width: options.width * scale,
      height: options.height * scale
    };
  }

Please note than my crop object contains the originalImageWidth and originalImageHeight so you need to workout those yourself, also it might contain a maxWidth and a maxHeight

and here’s my code for the upload of the base64

as an action I have

uploadBase64: function uploadBase64(base64, name = "test.png", type = "image/png") {
    ApplicationDispatcher.dispatch({
      actionType: ApplicationEvents.UPLOAD_BASE64,
      base64: base64,
      name: name,
      type: type
    });
  }

and in the store I have

uploadBase64(base64, name, type) {
    request.post('/api/sign/s3')
           .send({
             name: name,
             type: type,
             encoding: "base64",
             imageBinary: base64
           })
           .set('Accept', 'application/json')
           .end((err, res) => {
             if(this.hasError(err, res)) {
               this.emit(ApplicationEvents.FAILED_BASE64_UPLOAD, { name: name });
               return;
             }
             this.emit(ApplicationEvents.UPLOADED_BASE64, { name: name, url: res.body.url });
           });
  }

Let me know if you want the backend code as well, I’m happy to share it

0reactions
DPr00fcommented, Feb 25, 2016

If you’re doing cropping on the frontend you should really keep the image info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Weird overlay on applications - Microsoft Community
Whenever I open some specific applications, weird lines appear over them. I am attaching a screenshot for reference.
Read more >
Overlay Issue - Android Forums at AndroidCentral.com
Hello, I have been struggling to an overlay issue where, whenever I open a game there is a weird overlay on the left...
Read more >
[question] Strange overlay bug? Can't move the ... - Reddit
Can't move the overlay any higher than this and it sometimes disappears off the bottom of the screen (audio keeps playing), ie overlay...
Read more >
How to Fix Screen Overlay Error on Android - YouTube
Experiencing annoying “screen overlay ” errors on your Android device? Watch this video to learn how to fix Android screen overlay errors.
Read more >
[SOLVED] Strange overlay bug - MCreator
Hello, I have a problem with overlay. For no reason, it's completly poorly ... Overlay in editor, just a regular 32*18px imageOverlay in-game....
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