> ## Documentation Index
> Fetch the complete documentation index at: https://docs.komerza.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Images

> Turn the image file names in store data into URLs you can display

Store data carries image **file names**, not URLs. Every image a merchant uploads - logos, banners,
product, variant and category images - is served from one host:

```
https://ugc.komerza.com/{fileName}
```

Nothing else goes in the path: no store ID, no product ID.

> [!NOTE]
>
> Older pages use `https://user-generated-content.komerza.com/`. It serves the same files and keeps
> working, but use `ugc.komerza.com` for anything new.

## Where the file names are

| Source | Field | Notes |
| - | - | - |
| Product | `imageNames` | In display order |
| Variant | `imageNames` | Empty means "use the product's images" |
| Category | `imageName` | Optional |
| Store | `branding.iconFileName` | Easier: `getStoreLogoUrl()` |
| Store | `branding.bannerFileName` | Easier: `getStoreBannerUrl()` |

## A helper

```javascript theme={null}
const UGC = "https://ugc.komerza.com";

function imageUrl(fileName) {
  return fileName ? `${UGC}/${encodeURIComponent(fileName)}` : null;
}

// A variant's images, falling back to the product's
function variantImages(product, variant) {
  const names = variant.imageNames.length ? variant.imageNames : product.imageNames;
  return names.map(imageUrl);
}
```

## Store logo and banner

```javascript theme={null}
const logoUrl = await komerza.getStoreLogoUrl();
const bannerUrl = await komerza.getStoreBannerUrl();
```

Both are async and resolve to a full URL. When the merchant hasn't uploaded one they resolve to a
Komerza placeholder image, so check `store.branding?.iconFileName` or `bannerFileName` first if you'd
rather show nothing. See [Store Information](https://docs.komerza.com/storefront/store.md#logo-and-banner).

## Example: product gallery

```html theme={null}
<div class="gallery">
  <img id="main-image" alt="" />
  <div id="thumbnails"></div>
</div>

<script>
  async function loadGallery(idOrSlug) {
    const response = await komerza.getProduct(idOrSlug);
    if (!response.success) return;

    const product = response.data;
    const urls = product.imageNames.map((name) => `https://ugc.komerza.com/${name}`);
    const main = document.getElementById("main-image");

    if (urls.length === 0) {
      main.src = "/placeholder.png";
      return;
    }

    main.src = urls[0];
    main.alt = product.name;

    urls.forEach((url, index) => {
      const thumb = document.createElement("img");
      thumb.src = url;
      thumb.alt = `${product.name} - image ${index + 1}`;
      thumb.loading = "lazy";
      thumb.onclick = () => {
        main.src = url;
      };
      document.getElementById("thumbnails").append(thumb);
    });
  }
</script>
```

## Missing and broken images

A product can have no images, and an image can fail to load. Cover both:

```javascript theme={null}
function setImage(img, fileName, fallback = "/placeholder.png") {
  img.src = fileName ? `https://ugc.komerza.com/${fileName}` : fallback;
  img.onerror = () => {
    img.onerror = null;
    img.src = fallback;
  };
}
```

If your site sends a Content-Security-Policy, add `https://ugc.komerza.com` to `img-src` - see
[Built-in features](https://docs.komerza.com/storefront/built-in-features.md#content-security-policy).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.