diff --git a/client/src/components/content-blocks/ImageBlock.vue b/client/src/components/content-blocks/ImageBlock.vue index 5543f3c2..351b381f 100644 --- a/client/src/components/content-blocks/ImageBlock.vue +++ b/client/src/components/content-blocks/ImageBlock.vue @@ -1,7 +1,9 @@ @@ -22,6 +24,8 @@ import { ref, computed, onMounted } from 'vue'; const props = defineProps({ src: String, alt: String(''), + originalWidth: Number, + originalHeight: Number, }); const imgElement = ref(null); @@ -30,7 +34,6 @@ const height = ref(0); const loaded = ref(false); const modifiedUrl = computed(() => { - console.log('x, y, hdpi, retina:', width.value, height.value, isHighDensity(), isRetina()); const density = isHighDensity() ? 2 : 1; if (width.value) { @@ -52,6 +55,32 @@ const updateDimensions = () => { } }; +const handleLoad = () => { + loaded.value = true; // Set loaded to true when the image loads +}; + +const placeholderStyle = computed(() => { + const styles = { + width: '100%', + height: '100%', + }; + if (width.value) { + const scalingFactor = width.value / props.originalWidth; + console.log(props.originalWidth, width.value); + const scaledHeight = Math.round(props.originalHeight * scalingFactor); + const scaledWidth = Math.round(props.originalWidth * scalingFactor); + + if (props.originalWidth) { + styles.width = `${scaledWidth}px`; + } + if (props.originalHeight) { + styles.height = `${scaledHeight}px`; + } + console.log(styles); + return styles; + } +}); + const isHighDensity = () => { return ( (window.matchMedia && @@ -88,12 +117,10 @@ onMounted(updateDimensions); .wagtail-image { overflow: hidden; - &__image { width: 100%; - height: auto; /* Keep the image's aspect ratio intact */ - min-height: 100%; - + //height: 100%; + height: auto; /* Keep the image's aspect ratio intact */ } &__placeholder {