Unsplash

Provider documentation

Unsplash

Resize Unsplash image URLs while retaining their source query parameters.

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 { unsplashProvider } from '@desource/image/providers/unsplash';

export const imageConfig = {
  provider: 'unsplash',
  providers: {
    unsplash: unsplashProvider({
      "baseURL": "https://images.unsplash.com"
    })
  }
} satisfies ImageConfig;

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

Image source

Use the image URL returned by the Unsplash API, including its ixid query parameter.

https://images.unsplash.com/photo-1464822759023-fed622ff2c3b

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="https://images.unsplash.com/photo-1464822759023-fed622ff2c3b"
  alt="Sample image" width={800} height={500}
  modifiers={{
  "fit": "cover",
  "quality": 80
}}
/>

Provider options

baseURL
Defaults to the Unsplash image CDN.

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

Uses Imgix-style width, height, crop, format, auto, quality, fit and pixelDensity transformations.

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

  • Existing query parameters, including ixid, are retained unless explicitly overridden.
  • Use the image URL rather than the Unsplash photo webpage. Follow the Unsplash API guidelines for attribution and tracking.
← Back to all providers