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/transform

Upload image file, transform, receive binary response

POST /api/v1/transform/url

Fetch image from URL, transform, receive binary response

Request Parameters

Resize Options

ParameterTypeDescription
imageFileImage file (required for /transform)
urlStringImage URL (required for /transform/url)
widthIntegerTarget width in pixels
heightIntegerTarget height in pixels
percentIntegerResize by percentage (1-100). E.g., 50 = half size

Crop Options

ParameterTypeDescription
crop_xIntegerCrop start X coordinate
crop_yIntegerCrop start Y coordinate
crop_widthIntegerCrop width in pixels
crop_heightIntegerCrop height in pixels
gravityStringSmart crop position: center, north, south, east, west, northeast, northwest, southeast, southwest

Output Options

ParameterTypeDescription
qualityIntegerOutput quality 1-100 (default: 85)
formatStringOutput format: jpeg, png, webp, avif, auto
storeBooleanIf true, store image and return JSON with URL instead of binary

Response

By default, returns binary image data with metadata in headers:

HeaderDescription
Content-TypeMIME type (image/webp, image/jpeg, etc.)
X-Original-SizeOriginal file size in bytes
X-Transformed-SizeOutput file size in bytes
X-Output-FormatOutput format (webp, jpeg, etc.)
X-WidthOutput width in pixels
X-HeightOutput 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.