Make pixel art more reliably get pixelated rendering (#1077)
* Make pixel art more reliably get pixelated rendering Closes #289 * Run prettier
This commit is contained in:
parent
8d85158f91
commit
c731515b94
@ -2,10 +2,13 @@
|
|||||||
<img
|
<img
|
||||||
v-if="src"
|
v-if="src"
|
||||||
ref="img"
|
ref="img"
|
||||||
:class="`avatar size-${size} ${circle ? 'circle' : ''} ${noShadow ? 'no-shadow' : ''}`"
|
:class="`avatar size-${size} ${circle ? 'circle' : ''} ${noShadow ? 'no-shadow' : ''} ${
|
||||||
|
pixelated ? 'pixelated' : ''
|
||||||
|
}`"
|
||||||
:src="src"
|
:src="src"
|
||||||
:alt="alt"
|
:alt="alt"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
@load="updatePixelated"
|
||||||
/>
|
/>
|
||||||
<svg
|
<svg
|
||||||
v-else
|
v-else
|
||||||
@ -60,21 +63,20 @@ export default {
|
|||||||
default: 'eager',
|
default: 'eager',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
data() {
|
||||||
if (this.$refs.img && this.$refs.img.naturalWidth) {
|
return {
|
||||||
const isPixelated = () => {
|
pixelated: false,
|
||||||
if (this.$refs.img.naturalWidth < 96 && this.$refs.img.naturalWidth > 0) {
|
|
||||||
this.$refs.img.style.imageRendering = 'pixelated'
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
methods: {
|
||||||
if (this.$refs.img.naturalWidth) {
|
updatePixelated() {
|
||||||
isPixelated()
|
if (this.$refs.img && this.$refs.img.naturalWidth && this.$refs.img.naturalWidth <= 96) {
|
||||||
|
this.pixelated = true
|
||||||
} else {
|
} else {
|
||||||
this.$refs.img.onload = isPixelated
|
this.pixelated = false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -116,5 +118,9 @@ export default {
|
|||||||
&.no-shadow {
|
&.no-shadow {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.pixelated {
|
||||||
|
image-rendering: pixelated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user