API Endpoint Access URL
https://api.pixlab.io/resize
Get Your API Key & Try RESIZE Now ↗Description
Resize API endpoint scales images to desired dimensions. For proportional and intelligent scaling, consider using the smartresize endpoint.
Scales an image to the desired dimensions. Consider using smartresize for proportional & intelligent scaling of your images.
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input media URL. If uploading directly from your app, submit a multipart/form-data POST request. |
width |
Integer | Desired new width. If omitted, the height value will be applied. |
height |
Integer | Desired new height. If omitted, the width value will be applied. |
key |
String | Your PixLab API Key ↗. Can also be passed via WWW-Authenticate: header. |
Optional
Fields | Type | Description |
---|---|---|
blob |
Boolean | Returns image binary data when true (default: JSON with output URL). |
POST Request Body
Use when submitting POST requests instead of GET:
Allowed Content-Types:
multipart/form-data
application/json
Use multipart/form-data
for direct file uploads (see examples). For JSON, media must be pre-uploaded - use store endpoint first if needed.
HTTP Response
Fields | Type | Description |
---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
link |
URL | Link to the media output stored on pixlab.xyz storage server unless custom S3 keys are configured (see console for setup). |
id |
String | Unique media identifier. |
error |
String | Error message when status != 200. |
The API returns application/json
when the optional blob parameter is omitted. If blob is enabled, the endpoint returns raw binary data instead. Successful JSON responses contain these fields:
Required
No required parameters for this endpoint.
Optional
All parameters are optional for this endpoint.
Code Samples
import requests
def resize_image(image_url: str, width: int, height: int, api_key: str) -> str:
"""Resize an image using PixLab API and return the processed image URL."""
try:
response = requests.get(
'https://api.pixlab.io/resize',
params={
'img': image_url,
'key': api_key,
'width': width,
'height': height
},
timeout=10
)
response.raise_for_status()
data = response.json()
if data['status'] != 200:
raise ValueError(data.get('error', 'Unknown error occurred'))
return data['link']
except requests.exceptions.RequestException as e:
raise ConnectionError(f"API request failed: {e}") from e
except (KeyError, ValueError) as e:
raise ValueError(f"API response error: {e}") from e
# Example usage
if __name__ == "__main__":
try:
resized_url = resize_image(
image_url='http://www.drodd.com/images15/nature31.jpg',
width=640,
height=400,
api_key='My_PIXLAB_API_KEY'
)
print(f"Resized image location: {resized_url}")
except Exception as e:
print(f"Error: {e}")
fetch('https://api.pixlab.io/resize?img=http://www.drodd.com/images15/nature31.jpg&key=My_PIXLAB_API_KEY&width=640&height=400')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Pic location: " + reply.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$params = [
'img' => 'http://www.drodd.com/images15/nature31.jpg',
'key' => 'My_PIXLAB_API_KEY',
'width' => 640,
'height' => 400
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/resize?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
echo "Pic location: " . $reply['link'];
}
require 'net/http'
require 'json'
uri = URI('https://api.pixlab.io/resize')
params = {
'img' => 'http://www.drodd.com/images15/nature31.jpg',
'key' => 'My_PIXLAB_API_KEY',
'width' => 640,
'height' => 400
}
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 "Pic location: #{reply['link']}"
end
Similar API Endpoints
newimage, scale, minify, magnify, ar, smartcrop, grayscale, smartresize, remap, crop, mogrify, thumbnail, merge, composite, docscan, avatar, webfit