API Endpoint Access URL
https://api.pixlab.io/cropgif
Get Your API Key & Try CROPGIF Now ↗Description
The Crop GIF API is a specialized endpoint engineered to perform region extraction across all frames of an animated GIF file. By precisely applying cropping coordinates to every individual frame, this API ensures that animation delay, loops, and synchronization are perfectly preserved. Developers processing static formats like JPEG or PNG should instead utilize the standard crop endpoint.
HTTP Methods
GET, POST
HTTP Parameters
Required
| Fields | Type | Description |
|---|---|---|
img |
URL | Input GIF URL. If you want to upload your gif directly from your app, call store before invoking this endpoint. |
width |
Integer | Desired crop Width. If omitted, the height value is applied. |
height |
Integer | Desired crop Height. If omitted, the width value is applied. |
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 ↗. Alternatively, embed your key in the WWW-Authenticate: HTTP header to omit this parameter. |
Optional
| Fields | Type | Description |
|---|---|---|
blob |
Boolean | Returns JSON with output GIF link by default. Set to true to return raw GIF binary data instead. |
POST Request Body
Use when sending POST requests instead of GET.
Allowed Content-Types:
multipart/form-dataapplication/jsonUse multipart/form-data for direct file uploads (see REST API code samples). For JSON, media must be pre-uploaded. Call store to upload files before invoking this endpoint.
HTTP Response
| Fields | Type | Description |
|---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
link |
URL | Link to the gif output which is usually stored on the pixlab.xyz storage server unless you set your own S3 keys (refer to your dashboard ↗ on how to do that). |
id |
String | Unique media ID. |
error |
String |
Error message if status != 200.
|
The API returns application/json if the optional blob parameter is not set.
This endpoint returns a JSON Object after each call only if the optional blob parameter is not set. Otherwise, the GIF binary content is returned directly.
Code Samples
import requests
def crop_gif(image_url: str, api_key: str, x: int, y: int, width: int) -> None:
try:
response = requests.get(
'https://api.pixlab.io/cropgif',
params={
'img': image_url,
'key': api_key,
'x': x,
'y': y,
'width': width
},
timeout=10
)
response.raise_for_status()
data = response.json()
if data['status'] != 200:
print(f"Error: {data.get('error', 'Unknown error')}")
else:
print(f"GIF location: {data['link']}")
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
except (KeyError, ValueError) as e:
print(f"Invalid response format: {e}")
if __name__ == "__main__":
crop_gif(
image_url='http://cloud.addictivetips.com/wp-content/uploads/2009/testing.gif',
api_key='PIXLAB_API_KEY',
x=150,
y=70,
width=256
)
fetch('https://api.pixlab.io/cropgif?img=http://cloud.addictivetips.com/wp-content/uploads/2009/testing.gif&key=PIXLAB_API_KEY&x=150&y=70&width=256')
.then(response => response.json())
.then(data => {
if (data.status !== 200) {
console.log(data.error);
} else {
console.log("GIF location: " + data.link);
}
})
.catch(error => console.error('Error:', error));
<?php
function cropGif($imgUrl, $x, $y, $width, $apiKey) {
$baseUrl = 'https://api.pixlab.io/cropgif';
$params = [
'img' => $imgUrl,
'key' => $apiKey,
'x' => $x,
'y' => $y,
'width' => $width
];
$queryString = http_build_query($params);
$url = $baseUrl . '?' . $queryString;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
throw new Exception('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$reply = json_decode($response, true);
if ($httpCode != 200 || $reply['status'] != 200) {
throw new Exception($reply['error'] ?? 'Unknown error occurred');
}
return $reply['link'];
}
try {
$gifUrl = 'http://cloud.addictivetips.com/wp-content/uploads/2009/testing.gif';
$apiKey = 'PIXLAB_API_KEY';
$croppedGif = cropGif($gifUrl, 150, 70, 256, $apiKey);
echo "GIF location: " . $croppedGif;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>
require 'net/http'
require 'json'
uri = URI('https://api.pixlab.io/cropgif')
params = {
'img' => 'http://cloud.addictivetips.com/wp-content/uploads/2009/testing.gif',
'key' => 'PIXLAB_API_KEY',
'x' => 150,
'y' => 70,
'width' => 256
}
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 "GIF location: #{reply['link']}"
end
Similar API Endpoints
makegif, crop, resizegif, gifcomposite, meme, screencapture, drawtext, resize, scale, nsfw