Uncrop
Uncrop API
To generate new extensions of your picture, you can use the API available at https://clipdrop-api.co/uncrop/v1
.
The request must be an http POST
and its body must be a multipart/form-data
that has one images file & several text fields:
- a required
image_file
is the original image to process.- The original image should be a JPG, PNG or WebP, with a maximum resolution of 10 megapixels and a max file size of 30 Mb.
- an optional
extend_left
integer field corresponding to the number of pixels to add to the left of the image, maximum of 2k, defaults to 0. - an optional
extend_right
integer field corresponding to the number of pixels to add to the right of the image, maximum of 2k, defaults to 0. - an optional
extend_up
integer field corresponding to the number of pixels to add at the top of the image, maximum of 2k, defaults to 0. - an optional
extend_down
integer field corresponding to the number of pixels to add at the bottom of the image, maximum of 2k, defaults to 0. - an optional
seed
integer field between 0 and 100_000. Setting the seed makes the result deterministic (ie you will always get the same output).
note
You can set negative values for any of the extend parameters if you need to crop the image.
In case of success:
- the response mime-type is
image/jpeg
and the response image is the uncropped JPEG image. - the response headers will include a
x-remaining-credits
property to tell you how many credits you have left and ax-credits-consumed
property to tell you how many credits were consumed by your request.
In case of an error:
- the response mime-type is
application/json
, error type is indicated by the response status code and details are in the json body, ie
{ "error": "No api key provided" }
Authentication
Requests are authenticated with an API key, that you will find in your account page.
If your key has leaked, you can revoke it and request a new one in your account page.
Credits
1 successful uncrop API call = 1 credits.
Once logged in, you can claim 100 free Clipdrop APIs credits that you can use for development and debugging purposes. Once the 100 credits have been consumed, further calls will be rejected.
If you need more credits, you can purchase more credits via the following link.
Quota / Rate limiting
By default, each API key has a limit of 60 requests per minute for the uncrop API. Please let us know if you'd like higher values.
Examples
- CURL
- JavaScript
- Python
- Swift
- Kotlin
curl -X POST https://clipdrop-api.co/uncrop/v1 \
-H 'x-api-key: YOUR_API_KEY' \
-F 'image_file=@image.jpg' \
-F 'extend_left="120"' \
-F 'extend_down="-50"' \
-o result.png
const form = new FormData()
form.append('image_file', photo)
form.append('extend_left', '120')
form.append('extend_down', '-50')
fetch('https://clipdrop-api.co/uncrop/v1', {
method: 'POST',
headers: {
'x-api-key': YOUR_API_KEY,
},
body: form,
})
.then(response => response.arrayBuffer())
.then(buffer => {
// buffer here is a binary representation of the returned image
})
import requests
r = requests.post('https://clipdrop-api.co/uncrop/v1',
files = {
'image_file': ('image.jpg', image_file_object, 'image/jpeg'),
},
data = { 'extend_left': '120', 'extend_down' : '-50' },
headers = { 'x-api-key': 'YOUR_API_KEY'}
)
if (r.ok):
# r.content contains the bytes of the returned image
else:
r.raise_for_status()
import Alamofire;
let imageData = try Data(contentsOf: inputPath)
let headers: HTTPHeaders = [
"x-api-key": "YOUR_API_KEY"
]
AF.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(
imageData,
withName: "image_file",
fileName: "image.jpg",
mimeType: "image/jpeg"
)
multipartFormData.append(
"120",
withName: "extend_left"
)
multipartFormData.append(
"-50",
withName: "extend_down"
)
},
to: "https://clipdrop-api.co/uncrop/v1",
headers: headers
)
.responseData(queue: .global()) { response in
switch response.result {
case .success: do {
// response.data here is an in memory byte buffer of the returned image
}
case let .failure(error): print(error)
}
// this example uses the OkHttp library
// https://square.github.io/okhttp/
val client = OkHttpClient()
val requestBody =
MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(
"image_file",
"image.jpg",
File("docs/images/image.jpg").asRequestBody("image/jpeg".toMediaType())
)
.addFormDataPart("extend_left", "120")
.addFormDataPart("extend_down", "-50")
.build()
val request =
Request.Builder()
.header("x-api-key", "YOUR_API_KEY")
.url("https://clipdrop-api.co/uncrop/v1")
.post(requestBody)
.build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
// response.body().bytes() here is a byte array of the returned image
}
Responses
- 200
- 400
- 401
- 402
- 403
- 422
- 429
- 500
The body will contain the result image file.
Request is malformed or incomplete, non exhaustive causes can be:
- Missing image_file in request
- Input image format is not valid
- Image resolution is too big
Missing api key.
Your account has no remaining credits, you can buy more in your account page.
Invalid or revocated api key.
Input image is not acceptable.
Too many requests, blocked by the rate limiter.
You should space out your requests in time or contact us to increase your quota.
This may be a bug on our side.
Please contact us at contact@clipdrop.co so that we can investigate.
Support
Any question ? Contact us at contact@clipdrop.co or join the Slack community.