Images Videos Audio Pricing Docs View as Markdown (Agent) Get started
Human Agent

Astro integration

@pixelvault-dev/astro connects Astro 5 and Astro 6 sites to PixelVault with zero runtime dependencies. It ships three pieces you can use together or independently: a typed <PixelVaultImage /> component, a custom Astro ExternalImageService for astro:assets, and a Content Layer loader for syncing media collections at build time. Source: github.com/pixelvault-dev/astro · Package: @pixelvault-dev/astro.

npm install @pixelvault-dev/astro

1. <PixelVaultImage /> component

Use <PixelVaultImage /> directly on any page — even without registering the Astro integration. It defaults to fmt=auto, aligns responsive srcset breakpoints to PixelVault's discrete dimension whitelist, and exposes every edge transform (named presets, background removal, face-aware crop, effects, watermarks, and text overlays).

---
import PixelVaultImage from "@pixelvault-dev/astro/PixelVaultImage.astro";
---

<!-- Responsive image with automatic WebP/AVIF negotiation -->
<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="Product screenshot"
/>

<!-- Portrait cut-out with face-aware crop and background removal -->
<PixelVaultImage
  src="https://img.pixelvault.dev/proj_xyz789/img_portrait.jpg"
  width={400}
  height={400}
  fit="cover"
  gravity="face"
  zoom={0.7}
  segment="foreground"
  background="white"
  priority
  alt="Team member"
/>

Pass priority on above-the-fold hero images to set loading="eager", decoding="sync", and fetchpriority="high". Signed URLs, SVGs, and PDFs are passed through untouched so signatures are never broken.

2. Astro Image Service

Register pixelvault() in astro.config.mjs to allow img.pixelvault.dev (plus any custom domains) and offload Astro's built-in <Image />, <Picture />, and getImage() to PixelVault's edge — no build-time Sharp downloads or re-encoding.

// astro.config.mjs
import { defineConfig } from "astro/config";
import pixelvault from "@pixelvault-dev/astro";

export default defineConfig({
  integrations: [
    pixelvault({
      // Optional custom domains connected to your PixelVault projects:
      domains: ["cdn.example.com"],
      // Set to false to keep Sharp for local assets and only configure domains:
      imageService: true,
    }),
  ],
});

Then render PixelVault URLs with Astro's standard <Image /> component:

---
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 your project uses strict_transforms, pass strictPresets: true so only declared size presets are emitted.

3. Content Layer loader

Pull images, videos, or audio from your PixelVault project into an Astro Content Collection at build time. The loader reads PIXELVAULT_API_KEY from the environment by default (or accepts an explicit apiKey option), handles pagination, 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",
    // Optional filters: collectionId, tag, q, metadata, maxItems
  }),
});

export const collections = { gallery };

Render entries from the collection with <PixelVaultImage />, using AI-generated alt text when available:

---
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 ?? ""}
  />
))}

For videos and audio, use pixelvaultVideosLoader(), pixelvaultAudioLoader(), or pixelvaultLoader({ resource: "videos" | "audio" | "images" }).

URL helpers

Use the low-level helpers anywhere you need transformed URLs outside an <img> tag — Open Graph meta tags, JSON-LD, or RSS feeds:

import { buildPixelVaultUrl, buildPixelVaultSrcSet } from "@pixelvault-dev/astro";

const ogImage = buildPixelVaultUrl(heroUrl, { size: "social", format: "auto" });
const srcset = buildPixelVaultSrcSet(heroUrl, { format: "auto" }, { widths: [400, 800, 1200] });

Next steps