🖼️ Crop Image API

API để cắt ảnh từ file upload, URL hoặc base64

https://crop-api.176.vn/

Image Engine: IMAGICK (GD: ✓, ImageMagick: ✓)

📚 API Endpoints

POST /api/crop

Cắt ảnh từ file upload, URL hoặc base64

Parameters:
  • x (required): Tọa độ X của điểm bắt đầu cắt
  • y (required): Tọa độ Y của điểm bắt đầu cắt
  • width (required): Chiều rộng vùng cắt
  • height (required): Chiều cao vùng cắt
  • input_type (optional): Loại input - "file", "url", hoặc "base64" (mặc định: "file")
  • format (optional): Định dạng output - "jpg", "png", "gif", "webp"
  • background_color (optional): Màu nền - hex (#RRGGBB), rgb(r,g,b), hoặc array [r,g,b]
  • margins (optional): Object chứa margins và alignment (xem chi tiết bên dưới)
  • horizontal_alignment (optional): "left", "center", "right"
  • horizontal_margin (optional): Margin ngang (pixel)
  • vertical_alignment (optional): "top", "center", "bottom"
  • vertical_margin (optional): Margin dọc (pixel)
  • minimum_margin (optional): Margin tối thiểu (pixel)
  • image (required nếu input_type="file"): File ảnh upload
  • url (required nếu input_type="url"): URL của ảnh
  • image/base64 (required nếu input_type="base64"): Dữ liệu ảnh dạng base64
POST /api/crop Content-Type: multipart/form-data x: 100 y: 100 width: 300 height: 300 input_type: file image: [file]

GET /api/info

Lấy thông tin về API và các tính năng

💡 Ví dụ sử dụng

1. Cắt ảnh từ file upload (cURL)

curl -X POST "https://crop-api.176.vn/api/crop" \ -F "image=@/path/to/image.jpg" \ -F "x=100" \ -F "y=100" \ -F "width=300" \ -F "height=300"

2. Cắt ảnh từ URL (cURL)

curl -X POST "https://crop-api.176.vn/api/crop" \ -d "input_type=url" \ -d "url=https://example.com/image.jpg" \ -d "x=100" \ -d "y=100" \ -d "width=300" \ -d "height=300"

Lưu ý: API tự động detect định dạng ảnh từ URL (JPEG, PNG, GIF, WebP) dựa trên Content-Type header hoặc magic bytes của file.

3. Cắt ảnh từ base64 (JavaScript)

fetch('/api/crop', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ input_type: 'base64', image: 'data:image/jpeg;base64,/9j/4AAQSkZJRg...', x: 100, y: 100, width: 300, height: 300 }) }) .then(response => response.json()) .then(data => console.log(data));

🧪 Demo

Test API với file upload