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

Circular crop is flaky #64

Closed
adelespinasse opened this issue Sep 6, 2016 · 7 comments
Closed

Circular crop is flaky #64

adelespinasse opened this issue Sep 6, 2016 · 7 comments

Comments

@adelespinasse
Copy link

Create a ReactCrop with crop.aspect=1 and ellipse=true. Try shrinking and growing the circle. At some point when the circle is small and you're trying to make it larger, it will suddenly invert around its upper handle and/or become very small.

@sekoyo
Copy link
Owner

sekoyo commented Sep 7, 2016

Hi I'm not sure whether I'll try and fix it or deprecate it, it was added via PR from someone but feels extraneous to the core API and never sat well with me. I'll take a look and see if I can replicate this issue but I'm unlikely to add more complexity to the code to try and fix it (more likely to remove complexity from the code by removing it entirely - sorry!)

@adelespinasse
Copy link
Author

@dominictobias Would you consider keeping it if I submitted a PR to fix it? I haven't looked at the code at all, but I might consider it.

@sekoyo
Copy link
Owner

sekoyo commented Sep 9, 2016

Feel free to try, but you might find it tricky, also since this is just a visual change I would be surprised if the jumping didn't happen for rectangles. IIRC this should only happen when drawing a new shape but I'll have a try and see if I can replicate when I have some time in the next week.

@aaronshim
Copy link

Hi @adelespinasse, have you made any progress on this since? I'm running into a similar problem. Thanks!

@adelespinasse
Copy link
Author

@aaronshim It hasn't been at the top of my priorities. I just use a square crop. :/

@sekoyo
Copy link
Owner

sekoyo commented Jan 27, 2017

Sorry to say but this feature is going away in v2 I'm releasing probably this weekend, as it's a feature I don't have time/inclination to get working properly and I want to remove bloat from the codebase. v2 has a couple of breaking changes but no major difference so feel free to carry on using v1 if you want it

@sekoyo sekoyo closed this as completed Jan 27, 2017
@JeevaS0722
Copy link

JeevaS0722 commented Oct 2, 2020

try this

const canvas = getResizedCanvas(previewCanvas, crop.width, crop.height);
 const base64Image = canvas.toDataURL('image/png');
 console.log('base64Image', base64Image);
function getResizedCanvas(canvas, newWidth, newHeight) {
 const tmpCanvas = document.createElement('canvas');
 tmpCanvas.width = newWidth;
 tmpCanvas.height = newHeight;
 const ctx = tmpCanvas.getContext('2d');
 ctx.save();
 ctx.beginPath();
 ctx.arc(newWidth / 2, newHeight / 2, newHeight / 2, 0, Math.PI * 2, false);
 ctx.closePath();
 ctx.clip();

 ctx.drawImage(
   canvas,
   0,
   0,
   canvas.width,
   canvas.height,
   0,
   0,
   newWidth,
   newHeight
 );
 ctx.restore();
 // const base64Image = canvas.toDataURL('image/jpeg');
 return tmpCanvas;
}

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

No branches or pull requests

4 participants