Cloudflare Transformations

Provider documentation

Cloudflare Transformations

Transform images through a Cloudflare zone using /cdn-cgi/image/.

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

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

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

Image source

Use an origin-relative path or a remote source allowed by your Cloudflare zone.

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

Provider options

baseURL
Your Cloudflare zone origin. The adapter appends /cdn-cgi/image automatically.

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, gravity, background, blur, rotate and Cloudflare transformation parameters.

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 Image Transformations for the zone and allow the intended remote origins.
  • This is the zone transformation provider. For uploaded Cloudflare image IDs and named variants, use cloudflareimages.
  • No modifiers are added by default. With no requested transformations, the original absolute URL or baseURL-relative source is returned.
← Back to all providers