Skip to content

Serve Assets From Your Server

In this example, we explain how to configure the Creative Engine to use assets hosted on your own servers. While we serve all assets from our own CDN by default, it is highly recommended to serve the assets from your own servers in a production environment.

1. Register IMG.LY’s default assets

If you want to use our default asset sources in your integration, call engine.addDefaultAssetSources(baseURL: URL, exclude: Set<DefaultAssetSource>). Right after initialization:

let engine = Engine()
Task {
try await engine.addDefaultAssetSources()
}

This call adds IMG.LY’s default asset sources for stickers, vectorpaths and filters to your engine instance. By default, these include the following sources with their corresponding ids (as rawValue):

  • .sticker - 'ly.img.sticker' - Various stickers.
  • .vectorPath - 'ly.img.vectorpath' - Shapes and arrows.
  • .filterLut - 'ly.img.filter.lut' - LUT effects of various kinds.
  • .filterDuotone - 'ly.img.filter.duotone' - Color effects of various kinds.
  • .colorsDefaultPalette - 'ly.img.colors.defaultPalette' - Default color palette.
  • .effect - ly.img.effect - Default effects.
  • .blur - ly.img.blur - Default blurs.
  • .typeface - ly.img.typeface - Default typefaces.

If you don’t specify a baseURL option, the assets are parsed and served from the IMG.LY CDN. It’s it is highly recommended to serve the assets from your own servers in a production environment, if you decide to use them. To do so, follow the steps below and pass a baseURL option to addDefaultAssetSources. If you only need a subset of the categories above, use the exclude option to pass a set of ignored sources.

2. Copy Assets

Download the IMG.LY default assets from our CDN.

Copy the IMGLYEngine default asset folders to your application bundle. The default asset folders should be located in a new .bundle folder. It will create a nested Bundle object that can be loaded by your app. The folder structure should look like this:



3. Configure the IMGLYEngine to use your self-hosted assets

Next, we need to configure the SDK to use the copied assets instead of the ones served via IMG.LY CDN.

engine.addDefaultAssetSources offers a baseURL option, that needs to be set to an absolute URL, pointing to a valid Bundle or a remote location.

In case of using your own server, the baseURL should point to the root of your asset folder, e.g. https://cdn.your.custom.domain/assets:

let remoteURL = URL(string: "https://cdn.your.custom.domain/assets")!
Task {
try await engine.addDefaultAssetSources(baseURL: remoteURL)
}

In case of using a local Bundle, the baseURL should point to the .bundle folder, that we created in the previous step:

let bundleURL = Bundle.main.url(forResource: "IMGLYAssets", withExtension: "bundle")!
Task {
try await engine.addDefaultAssetSources(baseURL: bundleURL)
}