Image Conversion API Documentation

This API allows you to convert images between formats and apply advanced options such as resizing and effects. Send a POST request with multipart/form-data containing your image and options.

Endpoint

/api/convert

Request Parameters

  • file (required): The image file to convert (form field name: file).
  • outputFormat: Target format. One of: adobe98-jpg, srgb-jpg, png, webp, tiff, avif, heic.
  • imageEffect: none, blackAndWhite, sepia, negative.
  • resizeType: pixels or percentage.
  • width, height: Target size in pixels (if resizeType=pixels).
  • percentage: Resize percentage (if resizeType=percentage).
  • maintainAspectRatio: true or false.
  • inputFormat: adobe98-jpg or srgb-jpg (for color space conversion).

Example: JavaScript (fetch)

const form = new FormData();
form.append('file', fileInput.files[0]);
form.append('outputFormat', 'png');
form.append('imageEffect', 'none');
form.append('resizeType', 'pixels');
form.append('width', '100');
form.append('height', '100');
form.append('maintainAspectRatio', 'true');

fetch('/api/convert', {
  method: 'POST',
  body: form,
})
  .then(res => res.blob())
  .then(blob => {
    // handle the converted image
  });

Example: Python (requests)

import requests

with open('input.jpg', 'rb') as f:
    files = {'file': f}
    data = {
        'outputFormat': 'png',
        'imageEffect': 'none',
        'resizeType': 'pixels',
        'width': '100',
        'height': '100',
        'maintainAspectRatio': 'true',
    }
    response = requests.post('http://localhost:5173/api/convert', files=files, data=data)
    with open('output.png', 'wb') as out:
        out.write(response.content)

Example: cURL

curl -X POST   -F "file=@input.jpg"   -F "outputFormat=png"   -F "imageEffect=none"   -F "resizeType=pixels"   -F "width=100"   -F "height=100"   -F "maintainAspectRatio=true"   http://localhost:5173/api/convert

Example: C# (HttpClient)

using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

var client = new HttpClient();
var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(System.IO.File.ReadAllBytes("input.jpg")), "file", "input.jpg");
form.Add(new StringContent("png"), "outputFormat");
form.Add(new StringContent("none"), "imageEffect");
form.Add(new StringContent("pixels"), "resizeType");
form.Add(new StringContent("100"), "width");
form.Add(new StringContent("100"), "height");
form.Add(new StringContent("true"), "maintainAspectRatio");

var response = await client.PostAsync("http://localhost:5173/api/convert", form);
var result = await response.Content.ReadAsByteArrayAsync();
System.IO.File.WriteAllBytes("output.png", result);

Example: PHP (cURL)

$ch = curl_init();
$data = [
    'file' => new CURLFile('input.jpg'),
    'outputFormat' => 'png',
    'imageEffect' => 'none',
    'resizeType' => 'pixels',
    'width' => '100',
    'height' => '100',
    'maintainAspectRatio' => 'true',
];
curl_setopt($ch, CURLOPT_URL, 'http://localhost:5173/api/convert');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
file_put_contents('output.png', $response);

Response

The response will be the converted image file with appropriate Content-Type and Content-Disposition headers.

Errors

On error, the API returns a JSON object with an error message and appropriate HTTP status code.