Contentful

Provider documentation

Contentful

Resize and encode assets with the Contentful Images API.

Setup

Install the framework package and the core package for the provider import:

npm install @desource/image @desource/image-svelte

Save this as image.config.ts beside your example component. Replace sample domains and identifiers with your own.

import type { ImageConfig } from '@desource/image';
import { contentfulProvider } from '@desource/image/providers/contentful';

export const imageConfig = {
  provider: 'contentful',
  providers: {
    contentful: contentfulProvider({
      "baseURL": "https://images.ctfassets.net"
    })
  }
} satisfies ImageConfig;

Registering this provider makes it the default for the configured components. To mix services, register each provider and set provider="contentful" on the image that should use this one.

Image source

Use the asset URL from Contentful or its complete path including space, asset ID, hash and filename.

/space-id/asset-id/asset-hash/photo.jpg

Usage

The example uses the shared configuration above and the Svelte image component.

<script lang="ts">
  import { Image, setImageConfig } from '@desource/image-svelte';
  import { imageConfig } from './image.config';

  setImageConfig(imageConfig);
</script>

<Image
  src="/space-id/asset-id/asset-hash/photo.jpg"
  alt="Sample image" width={800} height={500}
  modifiers={{
  "format": "webp",
  "quality": 80,
  "fit": "cover"
}}
/>

Provider options

baseURL
Defaults to https://images.ctfassets.net. Set the correct regional delivery hostname if needed.

Pass shared defaults such as screens, domains, aliases and presets to the image configuration. Pass provider-specific defaults as modifiers in the provider factory.

Modifiers

Maps width, height, quality, format, focus, radius and background. Fit cover becomes crop, contain becomes fill, fill becomes scale and thumbnail becomes thumb.

Set dimensions on the component and pass service-specific operations through modifiers, as shown above. See the provider source for exact mappings and the service documentation for accepted values.

Provider notes

  • The adapter extracts the pathname from src and rebuilds the transformation query. Existing source query parameters are not retained.
  • When using an absolute regional asset URL, also configure the matching baseURL.
← Back to all providers