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>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { IMedia } from "@/types/media.model";
|
import { IMedia } from "@/types/media.model";
|
||||||
|
import { PropType } from "vue";
|
||||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||||
import LazyImageWrapper from "../Image/LazyImageWrapper.vue";
|
import LazyImageWrapper from "../Image/LazyImageWrapper.vue";
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ import LazyImageWrapper from "../Image/LazyImageWrapper.vue";
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class EventBanner extends 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;
|
picture!: IMedia | null;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -7,17 +7,21 @@ import { decode } from "blurhash";
|
||||||
import { Component, Prop, Ref, Vue } from "vue-property-decorator";
|
import { Component, Prop, Ref, Vue } from "vue-property-decorator";
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
export default class extends Vue {
|
export default class BlurhashImg extends Vue {
|
||||||
@Prop({ type: String, required: true }) hash!: string;
|
@Prop({ type: String, required: true }) hash!: string;
|
||||||
@Prop({ type: Number, default: 1 }) aspectRatio!: string;
|
@Prop({ type: Number, default: 1 }) aspectRatio!: string;
|
||||||
|
|
||||||
@Ref("canvas") readonly canvas!: any;
|
@Ref("canvas") readonly canvas!: any;
|
||||||
|
|
||||||
mounted(): void {
|
mounted(): void {
|
||||||
const pixels = decode(this.hash, 32, 32);
|
try {
|
||||||
const imageData = new ImageData(pixels, 32, 32);
|
const pixels = decode(this.hash, 32, 32);
|
||||||
const context = this.canvas.getContext("2d");
|
const imageData = new ImageData(pixels, 32, 32);
|
||||||
context.putImageData(imageData, 0, 0);
|
const context = this.canvas.getContext("2d");
|
||||||
|
context.putImageData(imageData, 0, 0);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { IMedia } from "@/types/media.model";
|
import { IMedia } from "@/types/media.model";
|
||||||
|
import { PropType } from "vue";
|
||||||
import { Component, Prop, Vue } from "vue-property-decorator";
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
||||||
import LazyImage from "../Image/LazyImage.vue";
|
import LazyImage from "../Image/LazyImage.vue";
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ const DEFAULT_PICTURE = {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class LazyImageWrapper extends Vue {
|
export default class LazyImageWrapper extends Vue {
|
||||||
@Prop({ required: true })
|
@Prop({ required: false, type: Object as PropType<IMedia | null> })
|
||||||
picture!: IMedia | null;
|
picture!: IMedia | null;
|
||||||
|
|
||||||
get pictureOrDefault(): Partial<IMedia> {
|
get pictureOrDefault(): Partial<IMedia> {
|
||||||
|
|
Loading…
Reference in a new issue