EmDash Picture

Responsive <picture> image catalog, AVIF/PNG variant resolver, and Astro/Svelte components for EmDash CMS.

View source
Public name@nodeart.io/emdash-picture

Or open Registry in your EmDash admin and search for this name.

Overview

EmDash Picture upgrades EmDash image fields and Portable Text articles to responsive <picture> elements with AVIF (image/avif) and lossless PNG (image/png) srcset ladders via EmDash's /_image endpoint.

Key Features

  • No upscaling: computeVariantDimensions() clamps every srcset candidate to known source bounds and omits width/height attributes when source dimensions are unavailable.
  • Canonical /_image URLs: Builds href, w, h, q, f in EmDash's canonical order and omits q for PNG so Cloudflare Images keeps PNG output lossless.
  • Safe pass-through: SVGs, GIFs, and third-party external URLs stay untouched as plain <img> fallbacks.
  • Multi-segment local storage keys: Supports both flat ULID storage keys and safe provider prefixes such as /_emdash/api/media/file/editorial-svg/....
  • Typed preset catalogs: Define site-specific widths, fits (contain / cover), AVIF quality, and sizes rules with defineImageCatalog(), or use DEFAULT_IMAGE_CATALOG (hero, wide, narrow, card, thumbnail, avatar, logo, icon).
  • UI & Edge caching helpers: Ships <MediaPicture> components for Astro and Svelte 5 plus isImmutableMediaRequest() for Cloudflare Worker / middleware edge caching.

Permissions

Plugins get only the capabilities they declare and you approve. Your EmDash admin lists these again before anything installs.

No special permissions requested

This plugin does not request access to protected EmDash features.

FAQ

Why omit q for PNG fallbacks?

Cloudflare Images treats f=png with q as quantized lossy PNG8. Omitting q produces crisp lossless PNG fallbacks while <source type="image/avif"> carries the lossy compressed AVIF candidates (q=76 by default).

How does it handle seeded or historical blog images missing dimensions?

When width and height are omitted, resolveMedia() emits the preset's responsive width ladder without fabricating HTML width/height attributes. If you enrich inline Portable Text image nodes from EmDash's MediaRepository (getDb()), <MediaPicture> automatically clamps the ladder to true source dimensions and emits exact width/height attributes to prevent CLS.

Can absolute media URLs be rewritten to relative /_emdash/api/media/file/... paths?

Yes. Pass allowedHosts: ['example.com', '*.example.com'] to resolveMedia(), resolvePictureRenderProps(), or <MediaPicture> so legacy absolute URLs on your own domains resolve cleanly across preview and production environments.

What does the public HTTP route return?

GET /_emdash/api/plugins/emdash-picture/resolve?src=<url>&preset=card validates inputs and returns JSON with media, sources, and img props for client-side or dynamic integrations.

Security

  • Zero capabilities requested (capabilities: [], allowedHosts: [], storage: {}).
  • Rejects non-HTTP(S)/relative protocols (javascript:, data:, protocol-relative //), path traversal (..), empty key segments, and untrusted external /_image origins.
  • Bounded public route inputs (widths max 16 integers capped at 4000px, quality 1..100, sizes/alt max 512 chars), returning HTTP 400 on invalid queries.

Changelog

0.1.2

  • Added allowedHosts prop support on Astro and Svelte <MediaPicture> components and generated TypeScript declarations.
  • Added $media seed-wrapper unwrapping, previewUrl support (for custom mediaProviders), local id/mediaId fallback when src is stripped, and multi-segment safe storage keys (such as editorial-svg/...).
  • Expanded documentation and EmDash Marketplace examples.

0.1.1

  • Published directly as a publisher PDS blob in EmDash Marketplace and via GitHub Actions OIDC with Sigstore provenance on npm.

0.1.0

  • Initial standalone release with defineImageCatalog, resolveMedia, resolvePictureRenderProps, <MediaPicture> for Astro/Svelte, and /_emdash/api/plugins/emdash-picture/resolve.

Installation

  1. Install the npm package in your EmDash Astro project (alongside registry installation for the resolve route):
bun add @nodeart/emdash-plugin-picture
  1. Register the plugin in astro.config.ts:
import { defineConfig } from 'astro/config';
import emdash from 'emdash/astro';
import { emdashPicture } from '@nodeart/emdash-plugin-picture';

export default defineConfig({
	integrations: [emdash({ plugins: [emdashPicture()] })]
});
  1. Render media fields in Astro or Svelte using <MediaPicture>:
---
import { MediaPicture } from '@nodeart/emdash-plugin-picture/astro';
import { DEFAULT_IMAGE_CATALOG, resolveMedia } from '@nodeart/emdash-plugin-picture/resolve-media';

const picture = resolveMedia(post.data.featured_image, ['card'], DEFAULT_IMAGE_CATALOG);
---
<MediaPicture media={picture} preset="card" alt={post.data.title} />
<script lang="ts">
	import MediaPicture from '@nodeart/emdash-plugin-picture/svelte/MediaPicture.svelte';
	import type { MediaProps } from '@nodeart/emdash-plugin-picture/resolve-media';

	let { picture, title }: { picture: MediaProps | null; title: string } = $props();
</script>

<MediaPicture media={picture} preset="card" alt={title} />
  1. For blog/article Portable Text bodies, pass a serializer for type.image that calls resolveMedia(mediaInput, [preset]) and renders <MediaPicture> (falling back to <PTImage> for external providers).

Keep exploring

More plugins like EmDash Picture

Browse by keyword, or see everything @nodeart.io publishes.

Install on your site

Open in EmDash

EmDash Picture

@nodeart.io/emdash-picture

Choose the EmDash site where you want to review this plugin. Nothing is installed until you confirm its permissions in that site's admin.

This browser will remember the site. You can change it next time.