API
四個接口:申請上傳網址、建立放大任務、查詢結果、失敗重試。包含參數規則、任務狀態和錯誤回傳。
POST
圖片上傳接口
/api/img_upload
cURL
curl -X POST https://bigjpg.com/api/img_upload \
-H 'X-API-KEY: YOUR_API_KEY' \
-d 'filename=small.jpg' \
-d 'filetype=image/jpeg'
# Use url from the response to upload the file to R2.
curl -X PUT --upload-file small.jpg \
-H 'Content-Type: image/jpeg' \
'UPLOAD_URL'
Python
import requests
filename = 'small.jpg'
filetype = 'image/jpeg'
r = requests.post(
url='https://bigjpg.com/api/img_upload',
headers={'X-API-KEY': 'YOUR_API_KEY'},
data={'filename': filename, 'filetype': filetype}
)
upload = r.json()
with open(filename, 'rb') as image:
requests.put(
url=upload['url'],
data=image,
headers={'Content-Type': filetype}
)
print(upload['fileurl']) # use as input in the enlarge API
- 付費會員可以調用 API
- 攜帶 API Key 呼叫此接口,取得臨時 R2 上傳網址和圖片公開網址
- 使用相同的 Content-Type 透過 PUT 上傳檔案,再將 fileurl 作為放大接口的 input
- 介面網址:
https://bigjpg.com
POST
放大圖片接口
/api/task/
cURL
curl -d '{"style": "art", "noise": "3", "x2": "1", "input": "YOUR_IMAGE_URL"}' \
-H 'X-API-KEY: YOUR_API_KEY' \
https://bigjpg.com/api/task/
Python
import json
import requests
data = {
'style': 'art',
'noise': '3',
'x2': '1',
'file_name': 'small.jpg',
'input': 'YOUR_IMAGE_URL'
}
r = requests.post(
url='https://bigjpg.com/api/task/',
headers={'X-API-KEY': 'YOUR_API_KEY'},
data=json.dumps(data)
)
print(r.json())
- 參數是JSON 格式
- style 參數有 'art', 'photo' 分別表示 '卡通插畫', '照片'
- noise 參數有 '-1', '0', '1 ', '2', '3' 分別表示降噪程度 '無', '低', '中', '>高', '最高'
- x2 參數有 '1', '2', ' 3', '4' 分別表示 2x, 4x, 8x, 16x
- input 參數是需要放大的圖片鏈接
- 建立成功會回傳 tid(任務 id)、minute(預估時間)和 remaining_api_calls(剩餘呼叫次數)。
GET
放大結果查詢接口
/api/task/{task_ids}
cURL
curl https://bigjpg.com/api/task/tid1,tid2,tid3,tid100
Python
import requests
r = requests.get(
url='https://bigjpg.com/api/task/tid1,tid2,tid3,tid100'
)
print(r.json())
- 一次可以查多個任務,用逗號分隔,單次最多 100 個。
- 每個任務回傳 {"status": ..., "url": ..., "size": ...},status 有 new、process、success、error 四種。
- 任務完成前,url 和 size 都是空的。
POST
任務重試接口
/api/task/{task_ids}
cURL
curl -X POST https://bigjpg.com/api/task/tid1,tid2,tid3,tid100
Python
import requests
r = requests.post(
url='https://bigjpg.com/api/task/tid1,tid2,tid3,tid100'
)
print(r.json())
錯誤回傳
status
- valid_api_key_required —— 請求標頭裡的 X-API-KEY 缺失或無法識別。先確認欄位名稱,再看這組 key 是否屬於尚未過期的付費帳號。
- requires_vip —— 帳號是免費版或已經到期。API 只對有效期內的付費帳號開放。
- month_limit —— 當月呼叫次數已經用完。每次成功建立任務都會回傳 remaining_api_calls,可以提前盯著這個數字。
- param_error —— 參數超出範圍:style 只能是 art 或 photo,noise 取 -1 到 3,x2 取 1 到 4(免費帳號 1 到 2)。
- input_url_error —— input 必須是外網可存取的 http:// 或 https:// 圖片網址。
X-API-KEY: 付費會員可以調用 API
可通過郵件 i@bigjpg.com 聯繫客服,單獨購買更多 API 接口調用次數