mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2025-01-20 22:30:20 +00:00
add gif data url to download
This commit is contained in:
parent
585812e703
commit
783782677a
3 changed files with 19 additions and 13 deletions
|
@ -2,7 +2,7 @@ import EncodeWorker from '@/services/encode.worker.js'
|
||||||
|
|
||||||
const PALETTE_SIZE = 255
|
const PALETTE_SIZE = 255
|
||||||
|
|
||||||
export function encode (imageDataList, imageWidth, imageHeight, paletteSize, delayTime) {
|
export function encode ({ imageDataList, imageWidth, imageHeight, delayTime }) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const worker = new EncodeWorker()
|
const worker = new EncodeWorker()
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ export function encode (imageDataList, imageWidth, imageHeight, paletteSize, del
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'done':
|
case 'done':
|
||||||
const dataUrl = 'data:image/gif;base64,' + btoa(payload.buffer.map((b) => String.fromCharCode(b)).join(''))
|
const base64Content = btoa(payload.buffer.map((b) => String.fromCharCode(b)).join(""))
|
||||||
|
const dataUrl = "data:image/gif;base64," + base64Content
|
||||||
resolve(dataUrl)
|
resolve(dataUrl)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
18
src/store.js
18
src/store.js
|
@ -21,7 +21,8 @@ export default new Vuex.Store({
|
||||||
status: false
|
status: false
|
||||||
},
|
},
|
||||||
downloading: {
|
downloading: {
|
||||||
status: false
|
status: false,
|
||||||
|
dataUrl: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
@ -50,11 +51,13 @@ export default new Vuex.Store({
|
||||||
stopEncoding (store) {
|
stopEncoding (store) {
|
||||||
store.encoding.status = false
|
store.encoding.status = false
|
||||||
},
|
},
|
||||||
startDownloading (store) {
|
startDownloading (store, dataUrl) {
|
||||||
store.downloading.status = true
|
store.downloading.status = true
|
||||||
|
store.downloading.dataUrl = dataUrl
|
||||||
},
|
},
|
||||||
stopDownloading (store) {
|
stopDownloading (store) {
|
||||||
store.downloading.status = false
|
store.downloading.status = false
|
||||||
|
store.downloading.dataUrl = null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -82,16 +85,11 @@ export default new Vuex.Store({
|
||||||
console.log(captureData)
|
console.log(captureData)
|
||||||
|
|
||||||
encode(captureData)
|
encode(captureData)
|
||||||
.then(clipDataUrl => {
|
.then(dataUrl => {
|
||||||
commit('stopEncoding')
|
commit('stopEncoding')
|
||||||
commit('startDownloading')
|
commit('startDownloading', dataUrl)
|
||||||
console.log(clipDataUrl)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error)
|
|
||||||
commit('stopEncoding')
|
|
||||||
commit('startDownloading')
|
|
||||||
})
|
})
|
||||||
|
.catch(error => console.error(error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="preview">
|
<div class="preview">
|
||||||
<img class="preview-visual" src="https://unsplash.it/320/320" alt="">
|
<img class="preview-visual" :src="downloading.dataUrl" alt="">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="download-btn btn btn--primary w100">Download GIF</button>
|
<button class="download-btn btn btn--primary w100">Download GIF</button>
|
||||||
|
@ -14,8 +14,15 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'download',
|
name: 'download',
|
||||||
|
computed: {
|
||||||
|
...mapState([
|
||||||
|
'downloading'
|
||||||
|
])
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
back () {
|
back () {
|
||||||
this.$store.commit('stopDownloading')
|
this.$store.commit('stopDownloading')
|
||||||
|
|
Loading…
Reference in a new issue