The package works with Astro 5 and Astro 6, ships with zero runtime dependencies, and is open source at github.com/pixelvault-dev/astro. We already dogfood it on pixelvault.dev itself (which is an Astro 6 static site).
npm install @pixelvault-dev/astro 1. Drop-in <PixelVaultImage /> component
If you want to keep Astro's default Sharp image service untouched for local assets, you can import <PixelVaultImage /> directly without adding any integration to astro.config.mjs:
---
import PixelVaultImage from "@pixelvault-dev/astro/PixelVaultImage.astro";
---
<PixelVaultImage
src="https://img.pixelvault.dev/proj_xyz789/img_abc123.jpg"
width={800}
height={450}
widths={[400, 800, 1200]}
sizes="(max-width: 800px) 100vw, 800px"
alt="Dashboard screenshot"
/> Under the hood, the component handles four details that are easy to get wrong by hand:
- Snapped responsive
srcset: widths are snapped up and deduplicated against PixelVault's discrete dimension whitelist (16–4000), so two nearby breakpoints never waste edge cache variants. - Clean proportional resizing:
widthandheightstay on the HTML<img>tag to prevent layout shift (CLS), while&h=is only sent to the CDN when you ask for a box fit (cover,crop,contain,pad) or omitwidth. - Full transform props: named presets (
size="social"or custom project presets), AI background removal (segment="foreground"), face-aware crop (gravity="face"), blur, sharpen, rotate, watermarks, and text overlays are all typed props. - Safe passthrough: HMAC-signed private URLs (
?token=…&expires=…), SVGs, and PDFs are never mutated, so signed links never break with a403.
2. Offload Astro's built-in <Image /> to the edge
If your pages already use Astro's standard <Image />, <Picture />, or getImage() from astro:assets, register the integration in astro.config.mjs:
// astro.config.mjs
import { defineConfig } from "astro/config";
import pixelvault from "@pixelvault-dev/astro";
export default defineConfig({
integrations: [
pixelvault({
domains: ["cdn.example.com"], // optional custom domains
defaultFormat: "auto",
}),
],
}); That adds img.pixelvault.dev (plus any custom domains) to Astro's allowed remote domains and registers PixelVault's ExternalImageService. Standard <Image /> tags now emit edge-transformed PixelVault URLs directly with zero Sharp processing:
---
import { Image } from "astro:assets";
---
<Image
src="https://img.pixelvault.dev/proj_xyz789/img_abc123.jpg"
width={800}
height={450}
widths={[400, 800, 1600]}
sizes="(max-width: 800px) 100vw, 800px"
alt="Hosted on PixelVault"
/> Local ESM-imported images, non-PixelVault remote URLs, signed URLs, and SVGs pass through untouched. If you prefer to keep Sharp for local files and only whitelist your PixelVault domains, pass imageService: false.
3. Sync media libraries into Content Collections
Astro's Content Layer API makes it straightforward to pull a PixelVault folder, collection, or AI-tagged subset into a typed collection at build time. The loader reads PIXELVAULT_API_KEY from your environment, paginates automatically, and prunes deleted assets between builds:
// src/content.config.ts
import { defineCollection } from "astro:content";
import { pixelvaultImagesLoader } from "@pixelvault-dev/astro/loader";
const gallery = defineCollection({
loader: pixelvaultImagesLoader({
folder: "portfolio",
kind: "image",
}),
});
export const collections = { gallery }; Because PixelVault's AI descriptions live on each image object, you can render a full responsive gallery with alt text straight from the collection:
---
import { getCollection } from "astro:content";
import PixelVaultImage from "@pixelvault-dev/astro/PixelVaultImage.astro";
const photos = await getCollection("gallery");
---
{photos.map(({ data }) => (
<PixelVaultImage
src={data.branded_url ?? data.url}
width={data.width ?? 800}
height={data.height ?? 600}
widths={[400, 800, 1200]}
sizes="(max-width: 768px) 100vw, 33vw"
alt={data.description?.alt ?? data.filename ?? ""}
/>
))} Need video or audio collections instead? Use pixelvaultVideosLoader() or pixelvaultAudioLoader() from @pixelvault-dev/astro/loader.
Get started
Read the full Astro integration docs, check the image transform reference, or browse the source and file issues on GitHub.