pleroma-fe/src/components/still-image/still-image.js

37 lines
867 B
JavaScript
Raw Normal View History

2018-01-29 18:47:26 +11:00
const StillImage = {
props: [
'src',
'referrerpolicy',
'mimetype',
'imageLoadError',
'imageLoadHandler'
2018-01-29 18:47:26 +11:00
],
data () {
return {
stopGifs: this.$store.getters.mergedConfig.stopGifs
}
},
2018-01-29 18:47:26 +11:00
computed: {
animated () {
return this.stopGifs && (this.mimetype === 'image/gif' || this.src.endsWith('.gif'))
2018-01-29 18:47:26 +11:00
}
},
methods: {
onLoad () {
this.imageLoadHandler && this.imageLoadHandler(this.$refs.src)
2018-01-29 18:47:26 +11:00
const canvas = this.$refs.canvas
if (!canvas) return
const width = this.$refs.src.naturalWidth
const height = this.$refs.src.naturalHeight
canvas.width = width
canvas.height = height
canvas.getContext('2d').drawImage(this.$refs.src, 0, 0, width, height)
2019-02-06 02:17:50 +11:00
},
onError () {
this.imageLoadError && this.imageLoadError()
2018-01-29 18:47:26 +11:00
}
}
}
export default StillImage