Skip to content

Commit

Permalink
Find the exact size for the image or use the minimum size for the image
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyperghost committed Dec 18, 2024
1 parent 4c6e55c commit c9726ad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ts/WoltLabSuite/Core/Component/Image/Cropper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,29 @@ class ExactImageCropper extends ImageCropper {
return super.showDialog();
}

protected getCanvas(): Promise<HTMLCanvasElement> {
// Calculate the size of the image in relation to the window size
const selectionRatio = Math.min(
this.cropperCanvasRect!.width / this.width,
this.cropperCanvasRect!.height / this.height,
);
const width = this.cropperSelection!.width / selectionRatio;
const height = width / this.configuration.aspectRatio;

const sizes = this.configuration.sizes
.filter((size) => {
return width >= size.width && height >= size.height;
})
.reverse();

const size = sizes.length > 0 ? sizes[0] : this.minSize;

return this.cropperSelection!.$toCanvas({
width: size.width,
height: size.height,
});
}

public async loadImage(): Promise<void> {
await super.loadImage();

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c9726ad

Please sign in to comment.