API Endpoint Access URL
https://api.pixlab.io/smartresize
Get Your API Key & Try SMARTRESIZE Now ↗Description
Proportional and intelligent scaling of images with the SMARTRESIZE API, ensuring optimal image quality and performance for developers and creators. Proportional & intelligent scaling of a given image.
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 new width. If this field is missing, then the height field is applied to this one. |
height |
Integer | Desired new height. If this field is missing, then the width field is applied to this one. |
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 or The PixLab Github Repository↗ 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
Fields | Type | Description |
---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
link |
URL | Link to the media 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 omitted. Otherwise, the raw media binary content is returned. The JSON response structure is documented above.
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."""
params = {
'img': image_url,
'key': api_key,
'width': width,
'height': height
}
try:
response = requests.get('https://api.pixlab.io/smartresize', params=params, 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
if __name__ == "__main__":
try:
image_url = "http://7-themes.com/data_images/out/3/6777986-blue-bird-pictures.jpg"
resized_url = resize_image(image_url, 640, 400, "My_PIXLAB_API_KEY")
print(f"Resized image location: {resized_url}")
except Exception as e:
print(f"Error: {e}")
fetch('https://api.pixlab.io/smartresize?img=http://7-themes.com/data_images/out/3/6777986-blue-bird-pictures.jpg&key=My_PIXLAB_API_KEY&width=640')
.then(response => response.json())
.then(data => {
if (data.status !== 200) {
console.log(data.error);
} else {
console.log("Pic location: " + data.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$params = [
'img' => 'http://7-themes.com/data_images/out/3/6777986-blue-bird-pictures.jpg',
'key' => 'My_PIXLAB_API_KEY',
'width' => 640,
'height' => 400
];
$query = http_build_query($params);
$url = 'https://api.pixlab.io/smartresize?' . $query;
$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);
if (curl_errno($ch)) {
die('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
die($reply['error']);
} else {
echo "Pic location: " . $reply['link'];
}
?>
require 'net/http'
require 'json'
uri = URI('https://api.pixlab.io/smartresize')
params = {
'img' => 'http://7-themes.com/data_images/out/3/6777986-blue-bird-pictures.jpg',
'key' => 'My_PIXLAB_API_KEY',
'width' => 640
}
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, resize, remap, crop, mogrify, thumbnail, merge, composite, docscan, avatar, webfit