API Endpoint Access URL
https://api.pixlab.io/scale
Get Your API Key & Try SCALE Now ↗Description
Scales an image proportionally using a percentage field, ideal for developers and creators looking to resize images efficiently. Scales an image proportionally using a percentage field.
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. |
scale |
Integer | Scaling percentage. A value between 1..500. For example, if this field is set to 50, then the image is scaled proportionally to half its size exactly like minify, 100 and the image is scaled proportionally to 2px its size and so forth. |
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 media binary contents is returned instead. |
POST Request Body
If you plan to use POST 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
Fields | Type | Description |
---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
link |
URL | Link to the image 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 image binary is returned. The JSON response contains the following fields:
Code Samples
import requests
def resize_image(image_url: str, api_key: str, scale_percentage: int) -> str:
"""Resize an image using PixLab API and return the processed image URL."""
params = {
'img': image_url,
'key': api_key,
'scale': scale_percentage
}
try:
response = requests.get('https://api.pixlab.io/scale', params=params)
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"Invalid API response: {e}") from e
if __name__ == '__main__':
try:
processed_url = resize_image(
image_url='http://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
api_key='My_PIXLAB_API_KEY',
scale_percentage=50
)
print(f"Processed image location: {processed_url}")
except Exception as e:
print(f"Error: {e}")
fetch('https://api.pixlab.io/scale?img=http://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg&key=My_PIXLAB_API_KEY&scale=50')
.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
<?php
$params = [
'img' => 'http://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
'key' => 'My_PIXLAB_API_KEY',
'scale' => 50
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/scale?' . 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/scale')
params = {
'img' => 'http://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
'key' => 'My_PIXLAB_API_KEY',
'scale' => 50
}
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, ar, mogrify, drawtext, minify, magnify, crop, resize, smartresize, remap, grayscale, thumbnail, merge, composite, docscan, avatar