-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Allow cropping an avatar before setting it #32565
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
12bfbf7
Fixed #31990
kerwin612 6628d67
Update profile.tmpl
kerwin612 0e1bb40
Merge branch 'main' into patch-17
kerwin612 dca4bb1
Merge branch 'main' into patch-17
kerwin612 c715200
Merge branch 'main' into patch-17
kerwin612 8863e92
code optimization
kerwin612 bfdb076
code optimization
kerwin612 651ee60
merge remote
kerwin612 19791a4
code optimization
kerwin612 6124e0f
Update locale_en-US.ini
kerwin612 c6919bb
fixed lint error
kerwin612 0b3b900
Merge branch 'main' into patch-17
kerwin612 e6b3a3f
Update web_src/js/features/comp/Cropper.ts
kerwin612 36945d7
Update web_src/js/features/comp/Cropper.ts
kerwin612 692fcff
Update web_src/js/features/comp/Cropper.ts
kerwin612 cd598bf
code optimization
kerwin612 50a4ceb
Merge branch 'main' into patch-17
kerwin612 53e9c63
Merge branch 'main' into patch-17
kerwin612 b64b368
Merge branch 'main' into patch-17
kerwin612 4d81186
Merge branch 'main' into patch-17
kerwin612 36cf69a
Remove CSS nesting
kerwin612 132f1a4
Remove global init
kerwin612 ea2a23c
Optimize the styling for mobile devices
kerwin612 5f893c3
improve
wxiaoguang 08d4c92
Update web_src/js/features/comp/Cropper.ts
kerwin612 4fc5a8d
Update web_src/js/features/comp/Cropper.ts
kerwin612 9d1513b
rename a repo init function by the way and fix ts error
wxiaoguang 82d0e9d
Update options/locale/locale_en-US.ini
kerwin612 55e06c1
Update web_src/js/features/user-settings.ts
kerwin612 57aecec
Merge branch 'main' into patch-17
kerwin612 7f49bb9
Revert 55e06c19b0ddb6ab8310fb8fcc36c7ef50bcc8a1
kerwin612 bff1595
Merge branch 'main' into patch-17
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import "cropperjs/dist/cropper.css"; | ||
|
||
.page-content.user.profile .cropper-panel .cropper-wrapper { | ||
max-width: 400px; | ||
max-height: 400px; | ||
} | ||
kerwin612 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {showElem} from '../../utils/dom.ts'; | ||
|
||
type CropperOpts = { | ||
container: HTMLElement, | ||
imageSource: HTMLImageElement, | ||
fileInput: HTMLInputElement, | ||
} | ||
|
||
export async function initCompCropper({container, fileInput, imageSource}: CropperOpts) { | ||
const {default: Cropper} = await import(/* webpackChunkName: "cropperjs" */'cropperjs'); | ||
let currentFileName = ''; | ||
let currentFileLastModified = 0; | ||
const cropper = new Cropper(imageSource, { | ||
aspectRatio: 1, | ||
viewMode: 2, | ||
autoCrop: false, | ||
crop() { | ||
const canvas = cropper.getCroppedCanvas(); | ||
canvas.toBlob((blob) => { | ||
const croppedFileName = currentFileName.replace(/\.[^.]{3,4}$/, '.png'); | ||
const croppedFile = new File([blob], croppedFileName, {type: 'image/png', lastModified: currentFileLastModified}); | ||
const dataTransfer = new DataTransfer(); | ||
dataTransfer.items.add(croppedFile); | ||
fileInput.files = dataTransfer.files; | ||
}); | ||
}, | ||
}); | ||
|
||
fileInput.addEventListener('input', (e: Event & {target: HTMLInputElement}) => { | ||
const files = e.target.files; | ||
if (files?.length > 0) { | ||
currentFileName = files[0].name; | ||
currentFileLastModified = files[0].lastModified; | ||
const fileURL = URL.createObjectURL(files[0]); | ||
imageSource.src = fileURL; | ||
cropper.replace(fileURL); | ||
showElem(container); | ||
} | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.