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

fix: add rounded option to the getCroppedCanvas method (#551) #1047

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ Change the crop box position and size with new data.
- `fillColor`: a color to fill any alpha values in the output canvas, the default value is the `transparent`.
- [`imageSmoothingEnabled`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled): set to change if images are smoothed (`true`, default) or not (`false`).
- [`imageSmoothingQuality`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/imageSmoothingQuality): set the quality of image smoothing, one of "low" (default), "medium", or "high".
- `rounded`: set `true` to use rounded values (the cropped area position and size data), the default value is `false`.

- (return value):
- Type: `HTMLCanvasElement`
Expand Down
2 changes: 1 addition & 1 deletion src/js/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export default {
y: initialY,
width: initialWidth,
height: initialHeight,
} = this.getData();
} = this.getData(!!options.rounded);
const ratio = source.width / Math.floor(canvasData.naturalWidth);

if (ratio !== 1) {
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ declare namespace Cropper {
fillColor?: string;
imageSmoothingEnabled?: boolean;
imageSmoothingQuality?: ImageSmoothingQuality;
rounded?: boolean;
}

export interface SetDataOptions {
Expand Down