Astro

The @freeplaceholder/astro package provides <Placeholder> and <Avatar> Astro components that render at build time with zero client-side JavaScript.

Installation

bash
npm install https://github.com/freeplaceholder/astro

Placeholder Component

astro
---
import Placeholder from "@freeplaceholder/astro/Placeholder.astro";
---

<Placeholder
  width={800}
  height={400}
  text="Hero Banner"
  format="webp"
  bg="3b82f6"
  textColor="ffffff"
  fontWeight="bold"
  rounded="lg"
/>

Placeholder Props

PropTypeDescription
widthnumberImage width in px (required)
heightnumberImage height in px (required)
formatImageFormatOutput format: svg, png, jpg, webp
bgstringBackground hex color
gradientGradientDirectionto-t, to-tr, to-r, to-br, to-b, to-bl, to-l, to-tl, radial
fromstringGradient start color — hex without #
viastringGradient middle color — hex without #
tostringGradient end color — hex without #
textColorstringText hex color
textstringCustom text overlay
textSizenumberFont size in px
textAlignTextAlignleft, center, right
textTransformTextTransformuppercase, lowercase, capitalize, none
textDecorationTextDecorationunderline, overline, line-through, none
letterSpacing`LetterSpacing \string`tighter, tight, wide, wider, widest, or px
fontWeightFontWeightFont weight
opacitynumber0–100
grayscalebooleanGrayscale filter
blurnumberGaussian blur 0–100 px
brightnessnumber0–200
contrastnumber0–200
hueRotatenumber0–360 degrees
invertbooleanInvert colors
saturatenumber0–200
sepiabooleanSepia tone
bordernumberBorder width in px
borderColorstringBorder hex color
borderStyleBorderStyleBorder style
rounded`Rounded \number`Border radius
lazybooleanEnable lazy loading (default: true)

Additional HTML <img> attributes are spread onto the rendered element.

Avatar Component

astro
---
import Avatar from "@freeplaceholder/astro/Avatar.astro";
---

<Avatar
  name="John Doe"
  size={64}
  format="png"
  fontWeight="bold"
  border={2}
  borderColor="ffffff"
/>

Avatar Props

PropTypeDescription
namestringName to derive initials from (required)
sizenumberSquare dimensions in px (default: 128)
formatImageFormatOutput format
bgstringBackground hex color
gradientGradientDirectionto-t, to-tr, to-r, to-br, to-b, to-bl, to-l, to-tl, radial
fromstringGradient start color — hex without #
viastringGradient middle color — hex without #
tostringGradient end color — hex without #
textColorstringText hex color
textDecorationTextDecorationunderline, overline, line-through, none
letterSpacing`LetterSpacing \string`Letter spacing
fontWeightFontWeightFont weight
opacitynumber0–100
blurnumberGaussian blur 0–100 px
brightnessnumber0–200
contrastnumber0–200
hueRotatenumber0–360 degrees
invertbooleanInvert colors
saturatenumber0–200
sepiabooleanSepia tone
grayscalebooleanGrayscale filter
bordernumberBorder width in px
borderColorstringBorder hex color
borderStyleBorderStyleBorder style
rounded`Rounded \number`Border radius
lazybooleanEnable lazy loading (default: true)

URL Helpers

For use in frontmatter or scripts:

astro
---
import { avatarUrl, placeholderUrl, snippetUrl } from "@freeplaceholder/astro";

const hero = placeholderUrl({ width: 1920, height: 1080, format: "webp", grayscale: true });
const avatar = avatarUrl({ name: "Alice", size: 96 });
const og = snippetUrl({ title: "Hello", format: "png" });
---

<img src={hero} alt="Hero" />
<img src={avatar} alt="Alice" />
<img src={og} alt="" width="1200" height="630" />

Overriding Base URL

astro
---
import { configure } from "@freeplaceholder/astro";

configure({ baseUrl: "https://my-custom-instance.com" });
---