Provider documentation
Directus
Request resized assets and transformation presets from Directus.
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 { directusProvider } from '@desource/image/providers/directus';
export const imageConfig = {
provider: 'directus',
providers: {
directus: directusProvider({
"baseURL": "https://cms.example.com/assets"
})
}
} satisfies ImageConfig; Registering this provider makes it the default for the configured components. To mix services, register each
provider and set provider="directus" on the image that should use this one.
Image source
Pass a Directus file ID, optionally followed by a filename. The example assumes the asset is publicly readable.
file-uuidUsage
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="file-uuid"
alt="Sample image" width={800} height={500}
modifiers={{
"format": "webp",
"quality": 80,
"withoutEnlargement": true
}}
/>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
Supports width, height, quality, format, fit, withoutEnlargement, key and transforms. The transforms array is JSON-encoded; duplicate operations are removed.
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
- Asset permissions and transformation limits are enforced by Directus. Client configuration does not authenticate private files.
- Use key for a named Directus transform without combining it with other transformation modifiers.
- Use transforms for a Sharp operation pipeline such as [["rotate", 90], ["grayscale"]].