API Endpoint Access URL
https://api.pixlab.io/rotate
Get Your API Key & Try ROTATE Now ↗Description
Rotate an image by a specified number of degrees, with empty spaces filled using the background color. Rotates an image the specified number of degrees. Note that empty spaces left over from rotating the image are filled with the background color.
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input image URL. For direct uploads, submit a multipart/form-data POST request. |
degree |
Float | Rotation angle in degrees (clockwise). |
key |
String | Your PixLab API Key ↗. Alternatively, use WWW-Authenticate: header. |
Optional
Fields | Type | Description |
---|---|---|
blob |
Boolean | Returns image binary if true (default: JSON response). |
color |
String | Background color (e.g., "red", "#fffeec"). Default: transparent. |
POST Request Body
For direct uploads instead of GET requests:
Allowed Content-Types:
multipart/form-data
application/json
Use multipart/form-data
for direct image uploads (see examples). For JSON, the image must be pre-uploaded (use store endpoint first).
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 image ID. |
error |
String | Error message if status != 200. |
The ROTATE endpoint 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 fields are documented above.
Code Samples
import requests
def rotate_image(image_url: str, degrees: int = 180, api_key: str = 'PIXLAB_API_KEY') -> str:
"""Rotate an image using the PixLab API and return the processed image URL."""
try:
response = requests.get(
'https://api.pixlab.io/rotate',
params={
'img': image_url,
'degree': degrees,
'key': api_key
},
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"Invalid API response: {e}") from e
if __name__ == '__main__':
try:
image_url = 'https://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg'
rotated_url = rotate_image(image_url)
print(f"Link to the rotated image: {rotated_url}")
except Exception as e:
print(f"Error: {e}")
const img = 'https://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg';
const degree = 180;
const apiKey = 'PIXLAB_API_KEY';
fetch(`https://api.pixlab.io/rotate?img=${encodeURIComponent(img)}°ree=${degree}&key=${apiKey}`)
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Link to the pic: " + reply.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$img = 'https://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg';
$degree = 180;
$key = 'PIXLAB_API_KEY';
$url = 'https://api.pixlab.io/rotate?' . http_build_query([
'img' => $img,
'degree' => $degree,
'key' => $key
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
echo "Link to the pic: " . $reply['link'];
}
require 'net/http'
require 'uri'
require 'json'
img = 'https://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg'
degree = 180
uri = URI.parse('https://api.pixlab.io/rotate')
params = { img: img, degree: degree, key: 'PIXLAB_API_KEY' }
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 "Link to the pic: #{reply['link']}"
end
Similar API Endpoints
polaroid, posterize, segment, favicon, quantize, raise, randomthreshold, grayscale, roll, roundcorners, setorientation, shadow, sepia, transverse, transpose, reverse, reflect