Skip to content

Commit

Permalink
fix: add rounded option to getCroppedCanvas method (fengyuanchen#551
Browse files Browse the repository at this point in the history
)
  • Loading branch information
7anshuai committed Mar 1, 2023
1 parent 759d65e commit c2946c5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
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 || false);
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

0 comments on commit c2946c5

Please sign in to comment.