Catch blurhash decoding errors
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
70bb3f3dd7
commit
1280b66f41
@ -5,6 +5,7 @@
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { IMedia } from "@/types/media.model";
|
||||
import { PropType } from "vue";
|
||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import LazyImageWrapper from "../Image/LazyImageWrapper.vue";
|
||||
|
||||
@ -14,7 +15,7 @@ import LazyImageWrapper from "../Image/LazyImageWrapper.vue";
|
||||
},
|
||||
})
|
||||
export default class EventBanner extends Vue {
|
||||
@Prop({ required: true, default: null })
|
||||
@Prop({ required: true, default: null, type: Object as PropType<IMedia> })
|
||||
picture!: IMedia | null;
|
||||
}
|
||||
</script>
|
||||
|
@ -7,17 +7,21 @@ import { decode } from "blurhash";
|
||||
import { Component, Prop, Ref, Vue } from "vue-property-decorator";
|
||||
|
||||
@Component
|
||||
export default class extends Vue {
|
||||
export default class BlurhashImg extends Vue {
|
||||
@Prop({ type: String, required: true }) hash!: string;
|
||||
@Prop({ type: Number, default: 1 }) aspectRatio!: string;
|
||||
|
||||
@Ref("canvas") readonly canvas!: any;
|
||||
|
||||
mounted(): void {
|
||||
const pixels = decode(this.hash, 32, 32);
|
||||
const imageData = new ImageData(pixels, 32, 32);
|
||||
const context = this.canvas.getContext("2d");
|
||||
context.putImageData(imageData, 0, 0);
|
||||
try {
|
||||
const pixels = decode(this.hash, 32, 32);
|
||||
const imageData = new ImageData(pixels, 32, 32);
|
||||
const context = this.canvas.getContext("2d");
|
||||
context.putImageData(imageData, 0, 0);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -9,6 +9,7 @@
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { IMedia } from "@/types/media.model";
|
||||
import { PropType } from "vue";
|
||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||
import LazyImage from "../Image/LazyImage.vue";
|
||||
|
||||
@ -31,7 +32,7 @@ const DEFAULT_PICTURE = {
|
||||
},
|
||||
})
|
||||
export default class LazyImageWrapper extends Vue {
|
||||
@Prop({ required: true })
|
||||
@Prop({ required: false, type: Object as PropType<IMedia | null> })
|
||||
picture!: IMedia | null;
|
||||
|
||||
get pictureOrDefault(): Partial<IMedia> {
|
||||
|
Loading…
Reference in New Issue
Block a user