feat: optimize image hash
Some checks failed
Deploy to SFTP Server / build (push) Failing after 18m17s

This commit is contained in:
2024-04-06 22:38:56 +02:00
parent f86661bbba
commit 68431e6b9c
8 changed files with 850 additions and 648 deletions

View File

@@ -10,12 +10,14 @@ interface Props {
maxWidth?: number;
}
import { rgbaToThumbHash } from "thumbhash";
import sharp from "sharp";
const { src: image, hash = true, alt, maxWidth } = Astro.props;
let thumbhash = "";
const s = await import("sharp");
const sharp = s.default;
if (hash) {
const scaleFactor = 100 / Math.max(image.width, image.height);
@@ -57,7 +59,7 @@ const sizes = [
src={image}
alt={alt}
data-thumbhash={thumbhash}
pictureAttributes={{ class: hash ? "block h-full" : "" }}
pictureAttributes={{ class: hash ? "block h-full relative" : "" }}
class={Astro.props.class}
widths={sizes.map((size) => size.width)}
sizes={sizes