REST API · v1

MakeFav API 文档

通过您自己的代码、构建脚本和 CI 流水线生成完整的 favicon 包。只需一次请求,即可将任意图片转换为 favicon.ico、Apple touch icon、Android 和 PWA 图标、web manifest 以及可直接粘贴的 HTML。

本页内容

快速开始

MakeFav API 是一个简单的 HTTPS + JSON REST API。所有端点都位于同一个基础 URL 下:

https://makefav.com/api/v1
  1. 创建免费账户
    注册、确认您的电子邮箱地址,并保持 MakeFav 新闻订阅处于启用状态——这是免费方案的唯一条件。
  2. 创建 API 密钥
    在您的账户中打开 API 密钥页面,创建一个个人密钥。密钥以 mf_ 开头,仅显示一次,请妥善保存。 管理 API 密钥
  3. 发送您的第一个请求
    将图片上传到 generate 端点,并保存返回的 ZIP 文件:
curl --fail-with-body -sS https://makefav.com/api/v1/generate \
  -H "Authorization: Bearer $MAKEFAV_API_KEY" \
  -F "[email protected]" \
  -F "app_name=My App" \
  -F "theme_color=#2f9e68" \
  -F "radius=20" \
  -o favicons.zip

Unzip favicons.zip, upload the files to your website and paste the HTML code from the end of readme-makefav.txt into the <head> of every page.

身份验证

对受保护端点的每个请求都必须包含个人 API 密钥。您可以随时在账户页面创建、命名和撤销密钥: API 密钥

Send the key as a bearer token in the Authorization header, or – if your HTTP client makes that awkward – in the X-API-Key header. Both are equivalent.

Authorization: Bearer mf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# or, alternatively
X-API-Key: mf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
密钥属于已确认电子邮箱地址且新闻订阅处于启用状态的用户(免费方案条件)。如果邮箱未确认、新闻订阅已关闭或账户被封禁,所有请求都会返回 403 Forbidden。
请像对待密码一样对待 API 密钥:将其保存在服务器或 CI 机密中,切勿放入浏览器代码、移动应用或公开仓库。如果密钥泄露,请立即撤销。

Missing or invalid keys return 401 Unauthorized. The GET /sizes and GET /openapi.json endpoints do not require a key.

速率限制

默认情况下,每个 API 密钥每小时最多可发出 100 次请求。每个已验证的响应都会告知您当前的使用情况:

响应头说明
X-RateLimit-Limit当前时间窗口内允许的最大请求数。
X-RateLimit-Remaining当前时间窗口内剩余的请求数。
X-RateLimit-Reset时间窗口重置时的 Unix 时间戳(秒,UTC)。
HTTP/1.1 200 OK
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 97
X-RateLimit-Reset: 1767225600

When the limit is exceeded the API responds with HTTP 429 and the error code rate_limited. Wait until the time in X-RateLimit-Reset before retrying – do not retry in a tight loop.

HTTP/1.1 429 Too Many Requests
Content-Type: application/json
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1767225600

{"error": {"code": "rate_limited", "message": "Rate limit exceeded. Try again after the reset time."}}

You can check your current quota at any time with GET /me.

端点

端点验证说明
POST /generateAPI 密钥创建完整的 favicon 包。
GET /meAPI 密钥您的账户及当前速率限制状态。
GET /sizes无生成器输出的所有图标文件及尺寸列表。
GET /openapi.json无机器可读的 OpenAPI 3.1 规范。

生成 favicon 包

POST/generate

根据一张源图片创建完整的 favicon 包。可通过以下三种方式之一发送图片:

内容类型图片字段说明
multipart/form-dataimage文件上传。推荐使用——效率最高。
application/jsonimage_base64Base64-encoded image, either raw base64 or a data URL such as data:image/png;base64,iVBOR….
application/jsonimage_url图片的公开 http 或 https URL。服务器会下载该图片(最大 10 MB)。

支持的输入格式:PNG、JPG、WebP、AVIF、GIF、BMP、SVG 和 ICO。最大文件大小:10 MB。

参数

所有参数均为可选。可以作为表单字段(multipart)或 JSON 属性发送。无效值将回退为默认值。

姓名类型 / 范围默认值说明
app_name字符串,最多 60 个字符My Website您的网站或应用名称,用于 manifest.json 和示例页面。
short_name字符串,最多 24 个字符app_name 的前 12 个字符显示在 Android 主屏幕图标下方的简称。
theme_color#rrggbb#ffffff浏览器界面颜色(theme-color meta 标签和 manifest)。
tile_color#rrggbb与 theme_color 相同Windows 开始屏幕磁贴的背景色。
backgroundtransparent | #rrggbbtransparent浏览器、Android 和 Windows 图标的背景。
apple_background#rrggbb#ffffffApple touch icon 和 maskable 图标的背景(iOS 不支持透明)。当 background 为某种颜色时将被忽略,并改用该颜色。
padding整数,0–40(%)0图片周围的留白,按图标尺寸的百分比计算。
radius整数,0–50(%)0圆角。50 表示圆形。不适用于 Apple 图标,iOS 会自行处理圆角。
zoom整数,50–400(%)100图片在图标内的缩放比例。大于 100 的值会裁剪图片。
offset_x, offset_y数字,-1 到 10按图标尺寸的比例,水平/垂直移动图片。
path字符串/图标在您服务器上存放的文件夹。用于 HTML 代码片段、manifest 和 browserconfig。
displaystandalone | fullscreen | minimal-ui | browserstandalone写入 manifest 的 PWA 显示模式。
pixelatedauto | 1 | 0auto为像素画提供锐利的最近邻缩放。auto 会对 64 px 及以下的源图片自动启用。
maskable1 | 01同时创建 maskable-icon-512x512.png,并为 Android 自适应图标预留安全区内边距。
ico_sizes以逗号分隔的列表:16、24、32、48、64、128、25616,32,48嵌入 favicon.ico 的尺寸。
groups以逗号分隔的列表:favicon、apple、android、msfavicon,apple,android,ms要生成的图标集:浏览器 favicon、Apple touch 图标、Android / PWA 图标和 Windows 磁贴。
formatzip | jsonzip响应格式 – 见下文。

响应

format=zip
Binary ZIP archive with Content-Type: application/zip and Content-Disposition: attachment. Default.
format=json
JSON object with the package id (32 hex characters), the html snippet for your <head> and a files array; each file has name, mime, size (bytes) and base64 contents.

示例请求 – multipart,返回 ZIP

curl --fail-with-body -sS https://makefav.com/api/v1/generate \
  -H "Authorization: Bearer $MAKEFAV_API_KEY" \
  -F "[email protected]" \
  -F "app_name=My App" \
  -F "theme_color=#2f9e68" \
  -F "radius=20" \
  -o favicons.zip
HTTP/1.1 200 OK
Content-Type: application/zip
Content-Disposition: attachment
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99
X-RateLimit-Reset: 1767225600

<binary ZIP data>

示例请求 – 使用图片 URL 的 JSON,返回 JSON

curl --fail-with-body -sS https://makefav.com/api/v1/generate \
  -H "Authorization: Bearer $MAKEFAV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "image_url": "https://example.com/logo.png",
    "app_name": "My App",
    "theme_color": "#2f9e68",
    "radius": 20,
    "groups": "favicon,apple,android",
    "format": "json"
  }'
{
  "id": "9f86d081884c7d659a2feaa0c55ad015",
  "html": "<link rel=\"apple-touch-icon\" sizes=\"57x57\" href=\"/apple-icon-57x57.png\">\n…\n<meta name=\"theme-color\" content=\"#2f9e68\">",
  "files": [
    {"name": "favicon.ico", "mime": "image/x-icon", "size": 15086, "base64": "AAABAAMAEBAAAAEAIABoBAAANgAAACAg…"},
    {"name": "favicon-16x16.png", "mime": "image/png", "size": 612, "base64": "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQ…"},
    {"name": "manifest.json", "mime": "application/json", "size": 1094, "base64": "ewogICAgIm5hbWUiOiAiTXkgQXBwIiwK…"}
  ]
}

获取您的账户

GET/me

返回 API 密钥所属的用户以及当前的速率限制状态。可用于验证密钥。需要身份验证,无需参数。

示例请求

curl -sS https://makefav.com/api/v1/me \
  -H "Authorization: Bearer $MAKEFAV_API_KEY"

示例响应

{
  "id": 1,
  "email": "[email protected]",
  "name": "Jane Doe",
  "rate_limit": {"limit": 100, "remaining": 97, "reset": 1767225600}
}

列出图标尺寸

GET/sizes

Returns every icon file the generator can produce, with its pixel size and group. No authentication and no parameters. The group value matches the groups parameter of POST /generate.

示例请求

curl -sS https://makefav.com/api/v1/sizes

示例响应

{
  "files": [
    {"name": "favicon-16x16.png", "size": 16, "group": "favicon"},
    {"name": "favicon-32x32.png", "size": 32, "group": "favicon"},
    {"name": "apple-touch-icon.png", "size": 180, "group": "apple"},
    {"name": "android-icon-192x192.png", "size": 192, "group": "android"},
    {"name": "ms-icon-144x144.png", "size": 144, "group": "ms"}
  ]
}

OpenAPI 规范

GET/openapi.json

返回此 API 的 OpenAPI 3.1 描述。无需身份验证。可导入 Postman、Insomnia 或 Swagger UI,也可用于为您的语言生成类型化客户端。

curl -sS https://makefav.com/api/v1/openapi.json -o makefav-openapi.json

错误

Successful requests return HTTP 200. Every error returns a JSON body with a stable, machine-readable code and a human-readable message. Always branch on the code, not on the message text.

HTTP/1.1 422 Unprocessable Content
Content-Type: application/json

{
  "error": {
    "code": "invalid_image",
    "message": "The uploaded file could not be decoded as an image."
  }
}
HTTP 状态错误代码含义
400bad_request请求格式错误,例如未发送图片或 JSON 正文无效。
401unauthorizedAPI 密钥缺失或无效。
403forbidden密钥所有者的邮箱未确认、已关闭新闻订阅,或账户已被封禁。
413file_too_large图片大小超过 10 MB。
415unsupported_type不支持该文件类型或请求内容类型。
422invalid_image文件无法解码为图片,或无法下载该图片 URL。
429rate_limited请求过多。请等待至 X-RateLimit-Reset。
500server_error我们这边出了点问题。请稍后重试;如问题持续,请联系支持团队。

输出文件

With all groups enabled, a package contains the files below. Files from disabled groups are left out.

文件尺寸分组
favicon.ico16, 32, 48 (可配置)始终
favicon-16x16.png16 × 16favicon
favicon-32x32.png32 × 32favicon
favicon-96x96.png96 × 96favicon
apple-icon-57x57.png57 × 57apple
apple-icon-60x60.png60 × 60apple
apple-icon-72x72.png72 × 72apple
apple-icon-76x76.png76 × 76apple
apple-icon-114x114.png114 × 114apple
apple-icon-120x120.png120 × 120apple
apple-icon-144x144.png144 × 144apple
apple-icon-152x152.png152 × 152apple
apple-icon-180x180.png180 × 180apple
apple-icon.png192 × 192apple
apple-icon-precomposed.png192 × 192apple
apple-touch-icon.png180 × 180apple
android-icon-36x36.png36 × 36android
android-icon-48x48.png48 × 48android
android-icon-72x72.png72 × 72android
android-icon-96x96.png96 × 96android
android-icon-144x144.png144 × 144android
android-icon-192x192.png192 × 192android
android-icon-512x512.png512 × 512android
web-app-manifest-192x192.png192 × 192android
web-app-manifest-512x512.png512 × 512android
maskable-icon-512x512.png512 × 512android
ms-icon-70x70.png70 × 70ms
ms-icon-144x144.png144 × 144ms
ms-icon-150x150.png150 × 150ms
ms-icon-310x310.png310 × 310ms

附加文件

文件包含说明
favicon.svg仅适用于未进行裁剪、缩放、内边距、圆角或背景设置的 SVG 输入您的 SVG 的净化副本,适用于支持矢量 favicon 的浏览器。
manifest.json, site.webmanifestandroid适用于 Android 和可安装 PWA 的 Web 应用清单(两份相同的副本)。
browserconfig.xmlms包含您的磁贴颜色的 Windows 磁贴配置。
readme-makefav.txt始终附有安装说明,末尾提供可直接用于 <head> 的 HTML 代码。

代码示例

Each example uploads logo.png with a few options and saves favicons.zip, handling API errors. Set the environment variable MAKEFAV_API_KEY to your API key first.

Multipart 上传:

# Multipart upload (recommended). --fail-with-body exits non-zero on HTTP errors
# and still saves the JSON error body, so you can inspect it.
curl --fail-with-body -sS https://makefav.com/api/v1/generate \
  -H "Authorization: Bearer $MAKEFAV_API_KEY" \
  -F "[email protected]" \
  -F "app_name=My App" \
  -F "theme_color=#2f9e68" \
  -F "radius=20" \
  -o favicons.zip \
  || { echo "Request failed:"; cat favicons.zip; rm -f favicons.zip; exit 1; }

包含 base64 编码图片的 JSON 正文(需要 jq):

# JSON body with a base64-encoded image (built with jq to avoid argument length limits)
base64 < logo.png | tr -d '\n' > logo.b64
jq -n --rawfile img logo.b64 \
  '{image_base64: $img, app_name: "My App", theme_color: "#2f9e68", radius: 20}' \
| curl --fail-with-body -sS https://makefav.com/api/v1/generate \
    -H "Authorization: Bearer $MAKEFAV_API_KEY" \
    -H "Content-Type: application/json" \
    --data-binary @- \
    -o favicons.zip \
  || { echo "Request failed:"; cat favicons.zip; rm -f favicons.zip; exit 1; }

HTML 用法

Upload all files to the folder you set with path, then paste the snippet into the <head> of every page. It is included at the end of readme-makefav.txt in the package and, with format=json, returned in the html field. Example for the options used in the code examples above:

<head>
  <meta charset="utf-8">
  <title>My App</title>

  <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
  <link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
  <link rel="icon" href="/favicon.ico" sizes="any">
  <link rel="manifest" href="/manifest.json">
  <meta name="msapplication-TileColor" content="#2f9e68">
  <meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
  <meta name="msapplication-config" content="/browserconfig.xml">
  <meta name="theme-color" content="#2f9e68">
</head>

部署后,请清除浏览器缓存或在隐私窗口中打开网站 – 浏览器会长期缓存 favicon。

更新日志

v1

  • MakeFav REST API 首次公开发布。
  • Endpoints POST /generate, GET /me, GET /sizes and GET /openapi.json.
  • 支持 ZIP 和 JSON 响应格式,以及 multipart、base64 和 URL 图片输入。
  • 个人 API 密钥,每小时 100 次请求。

版本 1 保持稳定:我们只会添加可选参数和字段。重大变更将以新版本发布,并提前通知。

支持

有问题、需要报告错误或需要更高的速率限制?我们很乐意提供帮助。请在消息中附上请求时间和错误代码,切勿包含您的 API 密钥。