lua.re/src/components/image.astro
luaneko 5fc6dafbbb
All checks were successful
Deploy website / deploy (push) Successful in 20s
Add sticker
2025-08-11 17:30:49 +10:00

34 lines
705 B
Plaintext

---
import { type UnresolvedImageTransform } from "astro";
import type { HTMLTag } from "astro/types";
import { getImage } from "astro:assets";
type Props = UnresolvedImageTransform & {
tag?: HTMLTag;
id?: string;
class?: string;
};
const { tag: Tag = "span", id, class: className, ...transform } = Astro.props;
const {
src,
options: { width, height },
} = await getImage({ format: "jpeg", ...transform });
---
<style>
.image {
background-size: contain;
background-position: center;
}
</style>
<Tag
id={id}
class:list={["image", className]}
style={{
aspectRatio: width && height ? width / height : undefined,
backgroundImage: `url(${JSON.stringify(src)})`,
}}
/>