Commit 8cda230f authored by Shpuld Shpludson's avatar Shpuld Shpludson

Merge branch '419-avatar-cropper-png' into 'develop'

Generate cropped avatar image in the original file type

Closes #419

See merge request pleroma/pleroma-fe!640
parents 3e4d465e ff9e55ae
...@@ -67,7 +67,7 @@ const ImageCropper = { ...@@ -67,7 +67,7 @@ const ImageCropper = {
submit () { submit () {
this.submitting = true this.submitting = true
this.avatarUploadError = null this.avatarUploadError = null
this.submitHandler(this.cropper, this.filename) this.submitHandler(this.cropper, this.file)
.then(() => this.destroy()) .then(() => this.destroy())
.catch((err) => { .catch((err) => {
this.submitError = err this.submitError = err
...@@ -88,14 +88,14 @@ const ImageCropper = { ...@@ -88,14 +88,14 @@ const ImageCropper = {
readFile () { readFile () {
const fileInput = this.$refs.input const fileInput = this.$refs.input
if (fileInput.files != null && fileInput.files[0] != null) { if (fileInput.files != null && fileInput.files[0] != null) {
this.file = fileInput.files[0]
let reader = new window.FileReader() let reader = new window.FileReader()
reader.onload = (e) => { reader.onload = (e) => {
this.dataUrl = e.target.result this.dataUrl = e.target.result
this.$emit('open') this.$emit('open')
} }
reader.readAsDataURL(fileInput.files[0]) reader.readAsDataURL(this.file)
this.filename = fileInput.files[0].name || 'unknown' this.$emit('changed', this.file, reader)
this.$emit('changed', fileInput.files[0], reader)
} }
}, },
clearError () { clearError () {
......
...@@ -157,8 +157,8 @@ const UserSettings = { ...@@ -157,8 +157,8 @@ const UserSettings = {
} }
reader.readAsDataURL(file) reader.readAsDataURL(file)
}, },
submitAvatar (cropper) { submitAvatar (cropper, file) {
const img = cropper.getCroppedCanvas().toDataURL('image/jpeg') const img = cropper.getCroppedCanvas().toDataURL(file.type)
return this.$store.state.api.backendInteractor.updateAvatar({ params: { img } }).then((user) => { return this.$store.state.api.backendInteractor.updateAvatar({ params: { img } }).then((user) => {
if (!user.error) { if (!user.error) {
this.$store.commit('addNewUsers', [user]) this.$store.commit('addNewUsers', [user])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment