# Logo API

Logo API 根据域名返回公司的 Logo 图片。它不需要 API 密钥，也不消耗积分（[积分和用量](/usage-and-quotas#credit-costs)），因此您可以将其 URL 直接放入 `<img>` 标签中。

## 请求

```text
GET https://logo.tomba.io/{domain}
```

| 参数        | 位置    | 说明                                                                                                                                                                                                                                   |
| ---------------- | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `domain`         | 路径  | 公司的域名，例如 `stripe.com`。子域名返回其可注册域名的 Logo，因此 `www.stripe.com` 返回 `stripe.com` 的 Logo。末尾的图片扩展名（如 `stripe.com.png` 中的扩展名）会被忽略。                    |
| `s` 或 `size`    | 查询 | 宽度和高度（像素），取值 1 到 512。Logo 会缩放为该尺寸的正方形 PNG；非正方形的 Logo 会被拉伸以适应。未设置 `s` 或设置 `s=80` 时，按存储时的原样返回 Logo，保持其原始格式和尺寸。 |
| `greyscale`      | 查询 | `true` 以灰度 PNG 格式返回 Logo。                                                                                                                                                                                                   |
| `d` 或 `default` | 查询 | 经过 URL 编码的 `http` 或 `https` 图片 URL，当 Tomba 没有该域名的 Logo 时返回此图片。它必须指向公共主机。                                                                                                                |

## 响应

成功的请求返回状态码 `200`，响应体中为图片：

- 设置了 `s` 或 `greyscale` 时，`Content-Type` 为 `image/png`。否则为 Logo 的存储格式：`image/png`、`image/jpeg`、`image/webp`、`image/avif` 或 `image/svg+xml`。
- `Content-Disposition` 为 `attachment; filename="<domain>.<extension>"`。因此，在浏览器标签页中打开该 URL 会下载图片；而 `<img>` 标签会显示图片。

当 Tomba 没有该域名的 Logo 时，API 仍返回状态码 `200`：

- 未设置 `d` 时，它返回 `s` × `s` 像素的占位 PNG（默认为 80 × 80），并带有 `Content-Disposition: attachment; filename=default.png`。检查该响应头即可区分占位图和 Logo。
- 设置了 `d` 时，它会获取您的图片并原样返回，同时带有 `Content-Disposition: attachment; filename="default"`。

## 错误

出错时返回带有 `error` 消息的 JSON 响应体，例如 `{"error": "size must be between 1 and 512"}`。

| 状态码 | 原因                                                                                                                           |
| ------ | ------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | 域名不是有效的域名，`s` 不是 1 到 512 之间的数字，或 `d` 不是公共主机上的 `http` 或 `https` URL。 |
| `502`  | Tomba 无法获取 `d` 处的图片，或该 URL 未返回状态码 `200`。                                                  |

## 示例

```html
<img
    src="https://logo.tomba.io/stripe.com?s=128"
    alt="Stripe logo"
    width="128"
    height="128"
/>
```

```bash
curl -o stripe.png "https://logo.tomba.io/stripe.com?s=200&greyscale=true"
```
