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

File processor image cropping #6047

Merged
merged 38 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
67cf2fb
Install cropperjs
Cyperghost Nov 5, 2024
3133112
Add `cropper.min.js`
Cyperghost Nov 5, 2024
29927c0
Add image cropper configuration
Cyperghost Nov 5, 2024
139d60d
Output the cropper configuration
Cyperghost Nov 5, 2024
c6dda3e
Open crop dialog if `cropperConfiguration` set
Cyperghost Nov 5, 2024
1163259
Display error message if images are too small
Cyperghost Nov 6, 2024
8bd9c70
Add `cropperContainer` around `cropper-canvas`
Cyperghost Nov 6, 2024
53d6539
Validate the file type
Cyperghost Nov 6, 2024
c5d033f
Check whether the user has canceled the dialog manually
Cyperghost Nov 6, 2024
f93cf87
Check whether the `cropper-selection` in `MinMaxImageCropper` limits …
Cyperghost Nov 6, 2024
a255d25
Remove sorting the sizes in js, server already does this
Cyperghost Nov 6, 2024
3a494ba
Correct comment
Cyperghost Nov 6, 2024
7c82a01
Update `cropper.min.js` to the current installed version
Cyperghost Nov 6, 2024
5a38bab
Run tsc
Cyperghost Nov 6, 2024
b88331c
Add since information
Cyperghost Nov 6, 2024
648fa48
Run `tsc`
Cyperghost Nov 6, 2024
b6691c4
Merge remote-tracking branch 'origin/6.2' into file-upload-image-crop
Cyperghost Nov 19, 2024
691d840
Merge branch '6.2' into file-upload-image-crop
Cyperghost Nov 28, 2024
2792414
Implement `FileRuntimeCache`, which also loads the thumbnails
Cyperghost Nov 29, 2024
9dc5693
Add `exifreader`
Cyperghost Nov 29, 2024
bb9d061
Add exifreader to `require.config.js`
Cyperghost Nov 29, 2024
e976c8d
Center the cropper selection in the canvas
Cyperghost Dec 4, 2024
dcb129b
Change the construct to private
Cyperghost Dec 4, 2024
7faa35e
Disable zoom
Cyperghost Dec 4, 2024
b140a08
Set the default selection to the maximum width
Cyperghost Dec 5, 2024
552d037
Round the numbers
Cyperghost Dec 5, 2024
983dc4d
Run `tsc`
Cyperghost Dec 5, 2024
9ad0476
Calculate the size of the cropper selection in relation to the window…
Cyperghost Dec 6, 2024
a9d93bf
Fixes the problem when the aspect ratio is less than 1, that the sele…
Cyperghost Dec 6, 2024
58dce4d
Recalculate cropper height on window resize.
Cyperghost Dec 9, 2024
243135e
Center `cropper-canvas`.
Cyperghost Dec 9, 2024
12a1c74
Add helper function to get the inner dimensions for an element
Cyperghost Dec 10, 2024
3575389
overwrites default values for `min-width` and `min-height`
Cyperghost Dec 10, 2024
1c6b805
Also note the maximum width that is available
Cyperghost Dec 10, 2024
fc90f96
Merge branch '6.2' into file-upload-image-crop
Cyperghost Dec 12, 2024
50bed09
Resize the image to the maximum that the browser can display in the d…
Cyperghost Dec 16, 2024
4c6e55c
Remove round
Cyperghost Dec 18, 2024
c9726ad
Find the exact size for the image or use the minimum size for the image
Cyperghost Dec 18, 2024
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
6 changes: 6 additions & 0 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ jobs:
- name: "Check 'sortablejs'"
run: |
diff -wu wcfsetup/install/files/js/3rdParty/Sortable.min.js node_modules/sortablejs/Sortable.min.js
- name: "Check 'cropperjs'"
run: |
diff -wu wcfsetup/install/files/js/3rdParty/cropper.min.js node_modules/cropperjs/dist/cropper.min.js
- name: "Check 'exifreader'"
run: |
diff -wu wcfsetup/install/files/js/3rdParty/exif-reader.js node_modules/exifreader/dist/exif-reader.js
152 changes: 152 additions & 0 deletions package-lock.json

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

12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"@woltlab/editor": "git+https://github.com/WoltLab/editor.git#54d7052a834e3b41e5fdacd8a17a4a4ea1b6e76c",
"@woltlab/visual-dom-diff": "git+https://github.com/WoltLab/visual-dom-diff.git#e5b51fce3157d1eda310566fc1f86101341d1fea",
"@woltlab/zxcvbn": "git+https://github.com/WoltLab/zxcvbn.git#5b582b24e437f1883ccad3c37dae7c3c5f1e7da3",
"cropperjs": "2.0.0-rc.2",
"emoji-picker-element": "^1.23.0",
"exifreader": "^4.25.0",
"focus-trap": "^7.6.1",
"html-parsed-element": "^0.4.1",
"perfect-scrollbar": "^1.5.6",
Expand All @@ -38,5 +40,15 @@
"tabbable": "^6.2.0",
"tslib": "^2.8.1",
"webpack-cli": "^5.1.4"
},
"exifreader": {
"include": {
"jpeg": true,
"png": true,
"webp": true,
"exif": [
"Orientation"
]
}
}
}
26 changes: 23 additions & 3 deletions ts/WoltLabSuite/Core/Component/File/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ImageResizer from "WoltLabSuite/Core/Image/Resizer";
import { AttachmentData } from "../Ckeditor/Attachment";
import { innerError } from "WoltLabSuite/Core/Dom/Util";
import { getPhrase } from "WoltLabSuite/Core/Language";
import { cropImage, CropperConfiguration } from "WoltLabSuite/Core/Component/Image/Cropper";

export type CkeditorDropEvent = {
file: File;
Expand Down Expand Up @@ -268,9 +269,28 @@ export function setup(): void {
return;
}

void resizeImage(element, file).then((resizedFile) => {
void upload(element, resizedFile);
});
if (element.dataset.cropperConfiguration) {
const cropperConfiguration = JSON.parse(element.dataset.cropperConfiguration) as CropperConfiguration;

void cropImage(element, file, cropperConfiguration)
.then((resizedFile) => {
void upload(element, resizedFile);
})
.catch((e) => {
if (e === undefined) {
// User closed the dialog.
return;
}

if (e instanceof Error) {
innerError(element, e.message);
}
});
} else {
void resizeImage(element, file).then((resizedFile) => {
void upload(element, resizedFile);
});
}
});

element.addEventListener("ckeditorDrop", (event: CustomEvent<CkeditorDropEvent>) => {
Expand Down
Loading
Loading