feat: optimize image hash
Some checks failed
Deploy to SFTP Server / build (push) Failing after 18m17s
Some checks failed
Deploy to SFTP Server / build (push) Failing after 18m17s
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user