快速开始
img2htm API 接收图片文件或 URL,返回 HTML、CSS、分离图片、结构化 JSON 和质量报告。 每月前 50 次预览调用免费。
- 创建账户 → 在控制台中创建密钥
POST https://img2htm.com/api/v1/reconstructwithimage_file,image_urlorimage_file_b64.- Receive HTML, CSS, separated assets, structured JSON and a quality report in one response.
轻松集成
提供 cURL、Node.js、Python、PHP、Ruby、Java、.NET 和 Swift 示例。
HTML + CSS + JSON
一次 API 调用即可返回 HTML、CSS、分离图片、结构化 JSON 和质量报告。
什么是点数?
1 点可完整转换一张纵向不超过 15,000 px 的图片。更长的图片会自动按多个点数计算。预览免费。
身份验证
通过 Authorization: Bearer 请求头或 X-Api-Key 请求头发送您的 API 密钥。
Authorization: Bearer i2h_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# or
X-Api-Key: i2h_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
示例代码
curl -X POST https://img2htm.com/api/v1/reconstruct \ -H "Authorization: Bearer i2h_your_api_key" \ -F "image_file=@product-page.jpg" \ -F "mode=full" \ -F "format=json"
import fs from 'node:fs';
const form = new FormData();
form.append('image_file', new Blob([fs.readFileSync('product-page.jpg')]), 'product-page.jpg');
form.append('mode', 'full');
const res = await fetch('https://img2htm.com/api/v1/reconstruct', {
method: 'POST',
headers: { Authorization: 'Bearer i2h_your_api_key' },
body: form,
});
const job = await res.json();
console.log(job.status, job.urls.html);import requests
with open('product-page.jpg', 'rb') as f:
r = requests.post(
'https://img2htm.com/api/v1/reconstruct',
headers={'Authorization': 'Bearer i2h_your_api_key'},
files={'image_file': f},
data={'mode': 'full', 'format': 'json'},
timeout=600,
)
job = r.json()
print(job['status'], job['sections'], job['urls']['zip'])<?php
$ch = curl_init('https://img2htm.com/api/v1/reconstruct');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer i2h_your_api_key'],
CURLOPT_POSTFIELDS => [
'image_file' => new CURLFile('product-page.jpg'),
'mode' => 'full',
],
]);
$job = json_decode(curl_exec($ch), true);
file_put_contents('index.html', $job['html']);require 'net/http'
require 'json'
uri = URI('https://img2htm.com/api/v1/reconstruct')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = 'Bearer i2h_your_api_key'
req.set_form([['image_file', File.open('product-page.jpg')], ['mode', 'full']], 'multipart/form-data')
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
job = JSON.parse(res.body)
puts job['status']HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://img2htm.com/api/v1/reconstruct"))
.header("Authorization", "Bearer i2h_your_api_key")
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString(
"image_url=https://example.com/page.jpg&mode=full"))
.build();
HttpResponse<String> res = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new("Bearer", "i2h_your_api_key");
using var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(File.ReadAllBytes("product-page.jpg")), "image_file", "product-page.jpg");
form.Add(new StringContent("full"), "mode");
var res = await http.PostAsync("https://img2htm.com/api/v1/reconstruct", form);
Console.WriteLine(await res.Content.ReadAsStringAsync());var request = URLRequest(url: URL(string: "https://img2htm.com/api/v1/reconstruct")!)
request.httpMethod = "POST"
request.setValue("Bearer i2h_your_api_key", forHTTPHeaderField: "Authorization")
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpBody = "image_url=https://example.com/page.jpg&mode=full".data(using: .utf8)
let (data, _) = try await URLSession.shared.data(for: request)
print(String(data: data, encoding: .utf8)!) 输出格式
format | 说明 |
|---|---|
json | Default. JSON object with html, css, content (structured sections + texts), assets (separated image URLs), quality and urls. |
html | Returns the reconstructed index.html document directly (text/html). |
zip | Streams a ZIP with index.html, styles.css, content.json, quality.json, sections/ and assets/. |
响应
{
"id": "3f9a1c2b7d4e6f80a1b2",
"status": "done",
"mode": "full",
"credits_used": 2,
"width": 860,
"height": 24000,
"sections": 16,
"quality": {
"text_accuracy": 97.4,
"visual_fidelity": 94.1,
"structure": 95.2,
"sections": 16,
"seconds": 41.8,
"provider": "anthropic:claude-sonnet-5",
"review": [],
"auto_pass": true
},
"urls": {
"html": "https://img2htm.com/api/v1/jobs/3f9a1c2b7d4e6f80a1b2/html",
"zip": "https://img2htm.com/en/convert/3f9a1c2b7d4e6f80a1b2/download",
"preview": "https://img2htm.com/en/convert/3f9a1c2b7d4e6f80a1b2/preview"
},
"assets": ["https://img2htm.com/files/results/3f9a1c2b7d4e6f80a1b2/assets/s01-a01.png"],
"html": "<!DOCTYPE html> ...",
"css": "/* img2htm base styles */ ...",
"content": { "sections": [ ... ], "texts": [ ... ] }
}
API 参考
Reconstruct an image
| 参数 | 类型 | 说明 |
|---|---|---|
image_file 必填* | file | Multipart upload. JPG, PNG or WebP, up to 25 MB. *One of image_file, image_url, image_file_b64 is required. |
image_url | string | Public HTTP(S) URL of the image. |
image_file_b64 | string | Base64-encoded image data. |
mode 可选 | full | preview | full (default) converts the whole image and charges 1 credit per 15,000 vertical px. preview converts only the top 3,000 px for free. |
lang 可选 | string | Output document language tag: ko, en, cn, tw, ja, mn, ru, th, id, vi, ar. Text is kept in its source language; this sets <html lang>/dir. |
format 可选 | json | html | zip | Response format (see above). |
async 可选 | 1 | Deprecated (always asynchronous): POST /reconstruct returns 202 Accepted with status: processing and a poll URL; poll GET /api/v1/jobs/{id} every 30–60 s until status: done (typically 30–45 min). |
Get a job
Returns the job object. Add ?include_html=1 to embed html, css and content.
Get the HTML document
Returns index.html as text/html.
Account
{ "email": "you@example.com", "credits": 38, "pixels_per_credit": 15000, "key": "i2h_ab12cd34…", "calls": 1207 }
Image generation API
Text-to-image, image variations and rendered translation (the image is redrawn with its text translated). All asynchronous; results are returned as absolute image URLs and can be chained straight into HTML reconstruction.
1) POST /api/v1/images/variations → 202 { "jobs":[{ "id":"…", "status":"processing", "poll":"…" }] }
2) GET /api/v1/images/{id} → { "status":"processing" } (poll every 3–5 s, usually 40–90 s)
3) GET /api/v1/images/{id} → { "status":"done", "images":["https://img2htm.com/files/generated/….jpg"] }
4) POST /api/v1/images/{id}/reconstruct → 202 HTML reconstruction job (poll GET /api/v1/jobs/{id})
Text → image
| 参数 | 类型 | 说明 |
|---|---|---|
prompt 必填 | string | Generation prompt (any language). |
count | 1–4 | Number of images (one job each). Default 1. |
ratio | auto 1:1 4:3 3:4 16:9 9:16 | Aspect ratio. Default auto. |
resolution | 1K 2K 4K | Default 2K. |
curl -X POST https://img2htm.com/api/v1/images/generate \
-H "Authorization: Bearer i2h_your_api_key" -H "Content-Type: application/json" \
-d '{"prompt":"Minimal skincare product hero shot on white marble, studio light","ratio":"1:1","resolution":"2K"}'
Image → variations
| 参数 | 类型 | 说明 |
|---|---|---|
image_file / image_url / image_file_b64 | file | string | Source image (one of these, or source_id / job_id). |
source_id | string | Id of a finished image job (optionally id#index) — chain variations of variations. |
job_id | string | Id of a reconstruction job — reuse the image you already uploaded. |
prompt | string | Optional instruction; the default keeps the product and style and changes composition/background. |
count, ratio, resolution | Same as generate. |
curl -X POST https://img2htm.com/api/v1/images/variations \
-H "Authorization: Bearer i2h_your_api_key" \
-F "image_file=@product.jpg" -F "count=2" -F "prompt=same product, night beach background"
Image translation (rendered)
Re-renders the image with every visible text translated into lang (layout, colours and product photos are preserved). Same source parameters as variations plus:
| 参数 | 类型 | 说明 |
|---|---|---|
lang 必填 | string | Target language: en ko ja cn tw vi th id ru mn ar es fr de pt it hi tr ms tl (see GET /api/v1/translate/languages). |
curl -X POST https://img2htm.com/api/v1/images/translate \
-H "Authorization: Bearer i2h_your_api_key" -H "Content-Type: application/json" \
-d '{"image_url":"https://example.com/detail-ko.jpg","lang":"ja"}'
Get / list image jobs
{
"ok": true, "id": "9c1f…", "kind": "variation", "status": "done", "progress": 100,
"prompt": "same product, night beach background", "ratio": "auto", "resolution": "2K",
"images": ["https://img2htm.com/files/generated/9c1f…-1.jpg"], "gen_seconds": 71.3,
"credits_used": 0, "created_at": "2026-09-04 13:20:11", "finished_at": "2026-09-04 13:21:30",
"poll": "https://img2htm.com/api/v1/images/9c1f…"
}
status: pending → processing → done | failed (error holds the reason; credits are refunded).
Generated image → HTML
Creates a reconstruction job from a finished image (index selects the image, default 0; mode full|preview; lang as in /reconstruct). Returns 202 with the job id — poll GET /api/v1/jobs/{id} like any reconstruction.
Translation · OCR API
Gemini-powered text translation and image OCR (+translation). Synchronous, responds within seconds.
Text translation
| 参数 | 类型 | 说明 |
|---|---|---|
text or texts | string | string[] | One text, or up to 500 strings (max 60,000 characters per request). |
target_lang 必填 | string | Target language code. |
source_lang | string | Optional; auto-detected by default. |
curl -X POST https://img2htm.com/api/v1/translate \
-H "Authorization: Bearer i2h_your_api_key" -H "Content-Type: application/json" \
-d '{"text":"리뷰티 스튜디오는 이미지 생성 API를 제공합니다.","target_lang":"en"}'
# → { "ok":true, "target_lang":"en", "model":"gemini-…", "translation":"Rebeauty Studio provides an image generation API." }
Image OCR (+ translation)
| 参数 | 类型 | 说明 |
|---|---|---|
image_file / image_url / image_file_b64 必填 | file | string | Image to read. |
translate_to | string | Optional target language: returns text (original) and translation. |
curl -X POST https://img2htm.com/api/v1/ocr -H "Authorization: Bearer i2h_your_api_key" \
-F "image_file=@banner.png" -F "translate_to=en"
# → { "ok":true, "text":"…extracted…", "translation":"…" }
Supported language codes and names.
速率限制
每分钟 60 张图片 per API key. When exceeded the API responds 429 Too Many Requests with a Retry-After: 60 header. Enterprise plans can raise this limit.
指数退避
On 429 or 5xx, retry with exponential backoff: wait 1s, 2s, 4s, 8s … up to 5 attempts, adding random jitter. Never retry 4xx errors other than 429.
delay = min(60, (2 ** attempt) + random(0, 1))
错误代码
| HTTP | 说明 |
|---|---|
400 | Missing image or unreadable URL. |
401 | Missing, invalid or revoked API key. |
402 | Insufficient credits. Response includes credits_needed and credits_available. |
413 | File exceeds the upload limit. |
415 | Unsupported image type. |
429 | Rate limit exceeded. |
500 | Conversion failed. Credits charged for the job are refunded automatically; error contains the reason. |
库与工具
集成、工具与应用
借助 Zapier 或 Make,您可以将 img2htm 连接到 2,000 多个应用。
Chrome 扩展
在任意网页上右键点击整张图片,即可转换为 HTML。
Windows / Mac / Linux
整文件夹批量转换、拖放操作、离线队列。与网页版使用相同点数。