curl -X POST https://jpghd.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'import requests
filename = 'small.jpg'
filetype = 'image/jpeg'
r = requests.post(
url='https://jpghd.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'])
- เรียก endpoint นี้ด้วย API key เพื่อรับ URL อัปโหลด R2 ชั่วคราวและ URL รูปภาพสาธารณะ
- อัปโหลดไฟล์ด้วย PUT โดยใช้ Content-Type เดิม จากนั้นใช้ fileurl เป็น input ใน API ขยายภาพ
curl -d '{"style": "photo_mid", "scratch": "", "color": "", "input": "YOUR_IMAGE_URL"}' \
-H 'X-API-KEY: YOUR_API_KEY' \
https://jpghd.com/api/task/
import requests
import json
data = {
'style': 'photo_mid',
'scratch': '',
'color': '',
'input': 'YOUR_IMAGE_URL'
}
r = requests.post(
url='https://jpghd.com/api/task/',
headers={'X-API-KEY': 'YOUR_API_KEY'},
data=json.dumps(data)
)
print(r.json())
- data ข้อมูลเป็นรูปแบบ JSON
- style สไตล์สามารถทำได้โดย photo(การปรับปรุง AI ของภาพถ่าย + การขยาย Lossless 4X), photo_mid(การปรับปรุง AI ของภาพถ่าย + การขยาย Lossless 2X), photo_slim(การปรับปรุง AI ของภาพถ่าย), art(การปรับปรุง AI ของภาพอาร์ตเวิร์ก + การขยาย Lossless 4X), art_mid(ปรับปรุง AI ของภาพอาร์ตเวิร์ค + ขยายแบบไม่สูญเสีย 2X), art_slim(ปรับปรุง AI ของภาพอาร์ตเวิร์ค)
- scratch คือ ไม่บังคับ การตั้งค่าสตริงว่างจะไม่ซ่อมแซมรอยขีดข่วน
- color เป็น ไม่บังคับ การตั้งค่าสตริงว่างจะไม่ทำให้ภาพมีสีสัน
- livephoto ไม่บังคับ การตั้งค่าสตริงว่างจะไม่สร้างภาพมหัศจรรย์
- return สถานะการส่งคืนอาจเป็น ok(หมายถึงสำเร็จ), conf_param_error(หมายถึงข้อผิดพลาดพารามิเตอร์ conf), exceed_limit(หมายถึงเครดิต api ไม่เพียงพอ)
curl https://jpghd.com/api/task/tid,tid,tidimport requests
r = requests.get(url='https://jpghd.com/api/task/tid,tid,tid')
print(r.json())
- ส่วนสีเหลืองคือรหัสงานที่ส่งกลับโดย Task Create API ซึ่งแยกด้วยเครื่องหมายจุลภาค
curl -X POST https://jpghd.com/api/task/tid,tid,tidimport requests
r = requests.post(url='https://jpghd.com/api/task/tid,tid,tid')
print(r.json())
- ส่วนสีเหลืองคือรหัสงานที่ส่งกลับโดย Task Create API ซึ่งแยกด้วยเครื่องหมายจุลภาค