Provider documentation
Strapi
Select uploaded Strapi image variants by breakpoint filename.
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 { strapiProvider } from '@desource/image/providers/strapi';
export const imageConfig = {
provider: 'strapi',
providers: {
strapi: strapiProvider({
"baseURL": "https://cms.example.com/uploads"
})
}
} satisfies ImageConfig; Registering this provider makes it the default for the configured components. To mix services, register each
provider and set provider="strapi" on the image that should use this one.
Image source
Use a filename relative to the uploads directory. A selected breakpoint is prepended to that filename.
photo_hash.jpgUsage
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="photo_hash.jpg"
alt="Sample image" width={800} height={500}
modifiers={{
"breakpoint": "medium"
}}
/>Provider options
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
The breakpoint modifier selects a pre-generated file, such as medium_photo_hash.jpg. Width, height, quality and format do not trigger image processing.
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
- Enable responsive upload variants in Strapi and select a breakpoint that exists for the asset.
- Without breakpoint, the original file is returned. Use strapi5 when working with the formats object and fallback variant selection.