Introduction
Welcome to the Hamster Tools API documentation. Our APIs provide powerful capabilities for developers to integrate our solutions into their applications.
Hamster Tools offers a suite of versatile APIs designed to help developers implement advanced functionality with minimal effort. Whether you're building a small project or a large-scale application, our APIs provide the tools you need.
Our API development roadmap is closely aligned with hamstertools.org.
This documentation will guide you through the process of integrating and utilizing our services effectively.
Authentication
All API requests require authentication using an API key. You can obtain your API key from your Hamster Tools dashboard after signing up for an account.
To authenticate your requests, include your API key in the headers of your HTTP requests:
Authorization: Bearer YOUR_API_KEY
Keep your API key secure and never share it publicly. If you believe your API key has been compromised, you can regenerate it from your dashboard.
1. Resize Image (By dimension)
Endpoint
/api/resize_image_dimensions
Description
Resizes an image to the specified dimensions while maintaining aspect ratio or fitting exactly as requested.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
image | File | Yes | The image file to be resized |
width | Number | At least one of width or height | Target width in pixels |
height | Number | At least one of width or height | Target height in pixels |
maintainAspectRatio | Boolean | No (default: true) | Whether to maintain the original aspect ratio |
returnType | String | No (default: 'file') | Response format: 'file' or 'json' |
Response
For returnType=file
:
- Returns the resized image file directly with appropriate Content-Type headers
For returnType=json
:
{
"success": true,
"data": {
"image": "data:image/jpeg;base64,...", // Base64 encoded image
"originalSize": {
"width": 1200,
"height": 800
},
"newSize": {
"width": 600,
"height": 400
},
"maintainAspectRatio": true
}
}
Error Responses
{
"success": false,
"error": "Error message"
}
Possible errors:
- No form data provided
- No image file provided
- At least one of width or height must be provided
- Failed to process image
Example
cURL:
curl -X POST \
https://hamstertools.com/api/resize_image_dimensions \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@/path/to/your/image.jpg" \
-F "width=800" \
-F "height=600" \
-F "maintainAspectRatio=true" \
-F "returnType=json"
2. Resize Image (By percentage)
Endpoint
/api/resize_image_percentage
Description
Resizes an image by a percentage of its original dimensions while maintaining the aspect ratio.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
image | File | Yes | The image file to be resized |
percentage | Number | Yes | Percentage to resize the image (e.g., 50 for 50%) |
returnType | String | No (default: 'file') | Response format: 'file' or 'json' |
Response
For returnType=file
:
- Returns the resized image file directly with appropriate Content-Type headers
For returnType=json
:
{
"success": true,
"data": {
"image": "data:image/jpeg;base64,...", // Base64 encoded image
"originalSize": {
"width": 1200,
"height": 800
},
"newSize": {
"width": 600,
"height": 400
},
"percentage": 50
}
}
Error Responses
{
"success": false,
"error": "Error message"
}
Possible errors:
- No form data provided
- No image file provided
- Percentage must be provided
- Invalid percentage value
- Failed to process image
Example
cURL:
curl -X POST \
https://hamstertools.com/api/resize_image_percentage \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "image=@/path/to/your/image.jpg" \
-F "percentage=50" \
-F "returnType=json"