Image Resize & Crop API
Transform images with resize and crop operations. Returns binary directly - perfect for WordPress plugins and CMS integrations.
Key Features
- ✓Returns binary directly - no temporary hosting
- ✓Resize by dimensions - width, height, or both
- ✓Resize by percentage - scale down proportionally
- ✓Crop with coordinates - precise x, y, width, height
- ✓Gravity-based crop - center, north, south, etc.
- ✓Format conversion - output as WebP, AVIF, JPEG
Endpoints
POST /api/v1/transformUpload image file, transform, receive binary response
POST /api/v1/transform/urlFetch image from URL, transform, receive binary response
Request Parameters
Resize Options
| Parameter | Type | Description |
|---|---|---|
image | File | Image file (required for /transform) |
url | String | Image URL (required for /transform/url) |
width | Integer | Target width in pixels |
height | Integer | Target height in pixels |
percent | Integer | Resize by percentage (1-100). E.g., 50 = half size |
Crop Options
| Parameter | Type | Description |
|---|---|---|
crop_x | Integer | Crop start X coordinate |
crop_y | Integer | Crop start Y coordinate |
crop_width | Integer | Crop width in pixels |
crop_height | Integer | Crop height in pixels |
gravity | String | Smart crop position: center, north, south, east, west, northeast, northwest, southeast, southwest |
Output Options
| Parameter | Type | Description |
|---|---|---|
quality | Integer | Output quality 1-100 (default: 85) |
format | String | Output format: jpeg, png, webp, avif, auto |
store | Boolean | If true, store image and return JSON with URL instead of binary |
Response
By default, returns binary image data with metadata in headers:
| Header | Description |
|---|---|
Content-Type | MIME type (image/webp, image/jpeg, etc.) |
X-Original-Size | Original file size in bytes |
X-Transformed-Size | Output file size in bytes |
X-Output-Format | Output format (webp, jpeg, etc.) |
X-Width | Output width in pixels |
X-Height | Output height in pixels |
Code Examples
Resize to Width (cURL)
curl -X POST https://api.kremlit.dev/api/v1/transform \ -F "[email protected]" \ -F "width=800" \ -F "format=webp" \ --output resized.webp
Center Crop (cURL)
curl -X POST https://api.kremlit.dev/api/v1/transform \ -F "[email protected]" \ -F "crop_width=500" \ -F "crop_height=500" \ -F "gravity=center" \ --output cropped.jpg
WordPress / PHP
<?php
$ch = curl_init('https://api.kremlit.dev/api/v1/transform');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => [
'image' => new CURLFile($image_path),
'width' => 800,
'format' => 'webp'
]
]);
$binary = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
// Save to WordPress uploads
$upload_dir = wp_upload_dir();
$filename = 'resized-' . time() . '.webp';
file_put_contents($upload_dir['path'] . '/' . $filename, $binary);JavaScript (Node.js)
const formData = new FormData();
formData.append('image', fs.createReadStream('photo.jpg'));
formData.append('width', '800');
formData.append('format', 'webp');
const response = await fetch('https://api.kremlit.dev/api/v1/transform', {
method: 'POST',
body: formData
});
// Get binary and save
const buffer = await response.arrayBuffer();
fs.writeFileSync('resized.webp', Buffer.from(buffer));
// Access metadata from headers
console.log('Output size:', response.headers.get('X-Transformed-Size'));
console.log('Dimensions:', response.headers.get('X-Width'), 'x', response.headers.get('X-Height'));Common Use Cases
WordPress Thumbnail Generation
Generate multiple thumbnail sizes on upload. Binary response allows direct save to wp-content/uploads.
Social Media Image Prep
Crop images to specific aspect ratios for Instagram (1:1), Twitter (16:9), or Facebook.
E-commerce Product Images
Standardize product photos to consistent dimensions with center crop.
Responsive Image Sets
Generate multiple sizes for srcset: 400w, 800w, 1200w from a single source.
Frequently Asked Questions
What is the maximum file size?
Maximum input file size is 10MB.
What image formats are supported?
Input: JPEG, PNG, WebP, AVIF, HEIC, GIF, BMP, TIFF. Output: JPEG, PNG, WebP, AVIF.
Is aspect ratio preserved when resizing?
Yes, if you specify only width or height, the other dimension scales proportionally. Specify both to force exact dimensions.
How does gravity-based cropping work?
Gravity determines where to anchor the crop. For example, gravity=north crops from the top center, gravity=southeast crops from bottom-right.
Can I resize and crop in one request?
Yes. Crop is applied first, then resize. This allows you to extract a region and scale it in a single API call.