# Show the right cover

> Pick the right size of a game's cover, lay it out before it loads, choose the box of the reader's language, and credit what needs credit.

Every game that has a cover comes with it in three sizes, its dimensions
and what the picture shows. Every file is stored and served by us: the API
never sends another site's address for an image.

## The three sizes

Each game object (in lists and on its own) carries:

| Field                       | What it is                                                        |
| --------------------------- | ----------------------------------------------------------------- |
| `image`                     | The main cover, the original edition's box front.                 |
| `medium`                    | The same, 500 pixels wide: cards and small screens.               |
| `thumbnail`                 | The same, 250 pixels wide: lists and search results.              |
| `imageWidth`, `imageHeight` | The size of `image` in pixels, to keep its place before it loads. |

All three are paths on the API (they start with `/v1/media/`): put
`https://api.thebgdb.org` in front. `medium` and `thumbnail` are the same
path as `image` when the cover is no wider than that size, and for
members' photos. A game with no cover we hold has `null` in all three.

```html
<img
  src="https://api.thebgdb.org/v1/media/covers/…-w500.jpg"
  srcset="
    https://api.thebgdb.org/v1/media/covers/…-w250.jpg 250w,
    https://api.thebgdb.org/v1/media/covers/…-w500.jpg 500w,
    https://api.thebgdb.org/v1/media/covers/….jpg 1200w
  "
  sizes="(max-width: 600px) 45vw, 250px"
  width="1200"
  height="1200"
  alt="Wingspan"
/>
```

Set `width` and `height` from `imageWidth` and `imageHeight` (they can be
`null`: then reserve a square), so the page does not jump when the image
arrives. Covers are not all square: show them whole (`object-fit:
contain`), never cropped.

## Is it a good cover?

- `imageKind` says what the picture shows: `box_front` is the whole front of
  the box; the [reference](https://docs.thebgdb.org/reference/) lists the others.
- `imageAcceptable` is `true` for a good cover: the whole front of the box,
  no person in it, a sharp enough picture, at least 300 pixels on its short
  side. `false` means a better one is wanted; you may prefer your own
  placeholder then.
- `imageLanguage` is the language of the edition on the box, when a source
  states it. It is usually `null`.

To list only games with a good cover, filter the list:

```sh
curl "https://api.thebgdb.org/v1/games?cover=ok&order=ranked&limit=24"
```

## The box in the reader's language

`GET /games/{id}` also returns `covers`: the main cover first (`primary:
true`), then the box of each other edition or name the game is sold under,
and members' photos of a box that say which edition they show. Each carries
its `language`, its `edition` and the `name` printed on it:

```ts
function coverFor(game, lang: string) {
const local = game.covers.find(
(c) => c.language === lang && c.kind === "box_front",
);
return local ?? game.covers.find((c) => c.primary) ?? null;
}
```

```python
def cover_for(game, lang):
    local = next((c for c in game["covers"] if c["language"] == lang and c["kind"] == "box_front"), None)
    return local or next((c for c in game["covers"] if c["primary"]), None)
```

## Credits

Some covers come from Wikimedia Commons, and some descriptions from
Wikipedia, under licences that ask for credit. `GET /credits` lists exactly
those, with the source, the licence and the author:

```sh
curl "https://api.thebgdb.org/v1/credits?kind=image&limit=50"
```

Show the credit wherever you show such an image. Nothing else needs a
credit line. Using the images and data is subject to the
[terms](https://thebgdb.org/terms#images).

:::tip[What to cache, and for how long]
A file's address never changes its content: cache images for as long as you
like (we send `immutable`). When a game's cover is replaced, the game
points to a new address. Re-read a game's fields at least daily if you show
them.
:::
