Upload an image and receive a compressed version with optional resizing and quality control.
The Image Compression API allows clients to upload images and receive optimized versions with optional resizing and compression parameters. The image is returned directly in the response, either as a base64 string or file stream.
webp
, jpeg
, or png
/api/v1/compress
Parameter | Type | Required | Description |
---|---|---|---|
image |
file (jpeg, png, webp) | Yes | The image file to upload and compress |
width |
integer | No | Target width (maintains aspect ratio if only width is provided) |
height |
integer | No | Target height (maintains aspect ratio if only height is provided) |
quality |
integer | No | Compression quality (10-100, default is 80) |
format |
string | No | Convert to jpeg , png , or webp |
base64 |
boolean | No | Return image as base64 string instead of stream (true/false) |
download |
boolean | No | Force file download if false returns it inline |
{ "message": "Image compressed successfully", "image_base64": "data:image/jpeg;base64,...", "extension": "jpeg", "mime": "image/jpeg", "size_kb": 123.45 }
POST https://hishuanigami.com/api/v1/image/compress Form Data: - image: [yourfile.png]
POST https://hishuanigami.com/api/v1/image/compress Form Data: - image: [yourfile.jpg] - width: 500 - height: 500 - quality: 70
POST https://hishuanigami.com/api/v1/image/compress Form Data: - image: [yourfile.png] - format: webp - base64: true
POST https://hishuanigami.com/api/v1/image/compress Form Data: - image: [yourfile.jpg] - format: jpeg - download: true
Returns compressed image as file or base64
Invalid file or parameters
{"message": "The image field is required."}
Rate limit exceeded
{"error": "Too many requests"}
Error during image processing
{"error": "Image processing failed"}