2018-01-29 08:47:26 +01:00
|
|
|
const StillImage = {
|
|
|
|
props: [
|
|
|
|
'src',
|
|
|
|
'referrerpolicy',
|
2019-02-02 20:11:36 +01:00
|
|
|
'mimetype',
|
2019-10-18 22:04:17 +02:00
|
|
|
'imageLoadError',
|
2019-02-18 06:03:26 +01:00
|
|
|
'imageLoadHandler',
|
2022-02-03 21:50:32 +01:00
|
|
|
'alt',
|
|
|
|
'height',
|
|
|
|
'width'
|
2018-01-29 08:47:26 +01:00
|
|
|
],
|
2018-03-12 00:31:33 +01:00
|
|
|
data () {
|
|
|
|
return {
|
2019-10-06 22:28:30 +02:00
|
|
|
stopGifs: this.$store.getters.mergedConfig.stopGifs
|
2018-03-12 00:31:33 +01:00
|
|
|
}
|
|
|
|
},
|
2018-01-29 08:47:26 +01:00
|
|
|
computed: {
|
2018-02-03 18:32:13 +01:00
|
|
|
animated () {
|
2018-03-12 00:31:33 +01:00
|
|
|
return this.stopGifs && (this.mimetype === 'image/gif' || this.src.endsWith('.gif'))
|
2022-02-03 21:50:32 +01:00
|
|
|
},
|
|
|
|
style () {
|
|
|
|
const appendPx = (str) => /\d$/.test(str) ? str + 'px' : str
|
|
|
|
return {
|
|
|
|
height: this.height ? appendPx(this.height) : null,
|
|
|
|
width: this.width ? appendPx(this.width) : null
|
|
|
|
}
|
2018-01-29 08:47:26 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2018-02-03 17:55:45 +01:00
|
|
|
onLoad () {
|
2020-09-29 12:18:37 +02:00
|
|
|
const image = this.$refs.src
|
|
|
|
if (!image) return
|
|
|
|
this.imageLoadHandler && this.imageLoadHandler(image)
|
2018-01-29 08:47:26 +01:00
|
|
|
const canvas = this.$refs.canvas
|
|
|
|
if (!canvas) return
|
2020-09-29 12:18:37 +02:00
|
|
|
const width = image.naturalWidth
|
|
|
|
const height = image.naturalHeight
|
2018-08-27 21:40:30 +02:00
|
|
|
canvas.width = width
|
|
|
|
canvas.height = height
|
2020-09-29 12:18:37 +02:00
|
|
|
canvas.getContext('2d').drawImage(image, 0, 0, width, height)
|
2019-02-05 16:17:50 +01:00
|
|
|
},
|
|
|
|
onError () {
|
|
|
|
this.imageLoadError && this.imageLoadError()
|
2018-01-29 08:47:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default StillImage
|