API Endpoint Access URL
https://api.pixlab.io/smartcrop
Get Your API Key & Try SMARTCROP Now ↗Description
Deprecated API endpoint. Use crop instead
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input media URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request. |
width |
Integer | Desired crop Width. If this field is missing, then the height field is applied for this one. |
height |
Integer | Desired crop Height. If this field is missing, then the width field is applied for this one. |
x |
Integer | The X coordinate of the cropped region's top left corner. |
y |
Integer | The Y coordinate of the cropped region's top left corner. |
key |
String | Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to. |
Optional
Fields | Type | Description |
---|---|---|
blob |
Boolean | By default, this API endpoint return a JSON Object holding the link to the image output. But, if this parameter is set to true then the image binary contents is returned instead. |
POST Request Body
This section details the requirements for using a POST request instead of a simple GET request.
Allowed Content-Types:
multipart/form-data
application/json
Use multipart/form-data
if you want to upload your media file directly (refer to the REST API code samples for a working example). If you are using JSON, then the media file must be already uploaded somewhere. Call store if you want to upload an image for example before invoking this endpoint.
HTTP Response
The SMARTCROP endpoint returns application/json
if the optional blob parameter is not set.
This endpoint returns a JSON Object after each call unless the blob parameter is specified, in which case the raw media binary is returned. The JSON response contains the following fields:
Fields | Type | Description |
---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
link |
URL | Link to the media output stored on the pixlab.xyz storage server unless custom S3 keys are configured (refer to your dashboard ↗ for configuration). |
id |
String | Unique media identifier. |
error |
String | Error message if status != 200. |
Code Samples
import requests
def extract_face(image_url: str, x: int, y: int, width: int, height: int, api_key: str) -> str:
"""Extract a face from an image using specified coordinates.
Args:
image_url: URL of the source image
x: X coordinate of the top-left corner
y: Y coordinate of the top-left corner
width: Width of the rectangle
height: Height of the rectangle
api_key: PixLab API key
Returns:
URL of the cropped image or error message
"""
try:
response = requests.get(
'https://api.pixlab.io/crop',
params={
'img': image_url,
'key': api_key,
'x': x,
'y': y,
'width': width,
'height': height
},
timeout=10
)
response.raise_for_status()
data = response.json()
if data['status'] != 200:
return f"Error: {data.get('error', 'Unknown error')}"
return f"Face location: {data['link']}"
except requests.exceptions.RequestException as e:
return f"Request failed: {str(e)}"
except (KeyError, ValueError) as e:
return f"Invalid response: {str(e)}"
if __name__ == "__main__":
result = extract_face(
image_url='http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
x=164,
y=95,
width=145,
height=145,
api_key='PIXLAB_API_KEY'
)
print(result)
fetch('https://api.pixlab.io/crop?img=http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg&key=PIXLAB_API_KEY&x=164&y=95&width=145&height=145')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Face location: " + reply.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$params = [
'img' => 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
'key' => 'PIXLAB_API_KEY',
'x' => 164,
'y' => 95,
'width' => 145,
'height' => 145
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/crop?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
echo "Face location: " . $reply['link'];
}
?>
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://api.pixlab.io/crop')
params = {
'img' => 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
'key' => 'PIXLAB_API_KEY',
'x' => 164,
'y' => 95,
'width' => 145,
'height' => 145
}
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
puts "Face location: #{reply['link']}"
end
Similar API Endpoints
newimage, scale, minify, magnify, ar, crop, resize, smartresize, remap, setresolution, resample, thumbnail, merge, composite, docscan, avatar, webfit