Oyyi

Convert Image Format

Convert an image from one format to another with control over quality, compression, and other format-specific options.

POST /api/image/convert

Request Parameters

ParameterTypeRequiredDescription
fileFileYesThe image file to convert. Supported input formats: JPEG, PNG, WebP, BMP, TIFF, GIF, HEIC, AVIF.
target_formatStringYesTarget format. Allowed values: "PNG", "JPEG", "WEBP", "BMP", "TIFF".
qualityIntegerNoThe quality level for lossy formats (JPEG, WebP). Range: 1-100. Default: 85.
optimizeBooleanNoWhether to apply additional optimization to reduce file size. Default: true.
losslessBooleanNoFor WebP format only: whether to use lossless compression. Default: false.
compression_levelIntegerNoFor PNG format only: the compression level. Range: 0-9. Default: 6.
progressiveBooleanNoFor JPEG format only: whether to create a progressive JPEG. Default: false.
strip_metadataBooleanNoWhether to remove EXIF and other metadata from the image. Default: false.

Response

Returns the image converted to the specified format.

Example Request

    // example.sh
curl -X POST "https://oyyi.xyz/api/image/convert"   -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@image.jpg" \
  -F "target_format=WEBP" \
  --output converted.webp
  

Example with Python

    // convert.py
import requests

url = "https://oyyi.xyz/api/image/convert"

files = {
    'file': open('image.jpg', 'rb')
}

data = {
    'target_format': 'WEBP'
}

response = requests.post(url, files=files, data=data)

# Save the converted image
with open('converted.webp', 'wb') as f:
    f.write(response.content)
  

Example with JavaScript

    // convert.js
// Using fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('format', 'webp');
formData.append('quality', '85');

fetch('https://oyyi.xyz/api/image/convert', {
  method: 'POST',
  body: formData
})
.then(response => response.blob())
.then(blob => {
  // Create a URL for the blob
  const url = URL.createObjectURL(blob);

  // Create a link to download the image
  const a = document.createElement('a');
  a.href = url;
  a.download = 'converted.webp';
  a.click();

  // Clean up by revoking the URL
  URL.revokeObjectURL(url);
})
.catch(error => console.error('Error:', error));
  

Format Comparison

FormatTransparencyCompressionFile SizeBest For
JPEGNoLossySmallPhotographs, complex images with many colors
PNGYesLosslessMedium to LargeGraphics with transparency, screenshots, images with text
WebPYesLossy or LosslessVery SmallWeb images, best balance of quality and size
BMPLimitedNoneVery LargeSimple graphics, compatibility with older systems
TIFFYesVariousLargePrint, publishing, archival, high-quality images
GIFYesLosslessMediumAnimations, simple graphics with few colors

How It Works

The convert endpoint changes the format of an image:

  1. Image Loading: The uploaded image is loaded into memory, automatically detecting its format.
  2. Format Conversion: The image is converted to the target format specified by the format parameter.
  3. Quality Setting: For lossy formats (JPEG, WebP), the specified quality level is applied.
  4. Format-Specific Options: Additional options are applied based on the target format:
    • For WebP: lossless compression if specified
    • For PNG: compression level for file size optimization
    • For JPEG: progressive encoding if specified
  5. Optimization: If optimize is true, additional algorithms are applied to reduce file size without significant quality loss.
  6. Metadata Handling: If strip_metadata is true, EXIF and other metadata are removed from the image.

The result is an image in the requested format, optimized according to the specified parameters.

Format-Specific Options

JPEG Options

  • quality: Controls compression level (1-100). Higher values preserve more detail but result in larger files.
  • progressive: Creates a progressive JPEG that loads gradually, showing a low-resolution version first.

PNG Options

  • compression_level: Controls the compression effort (0-9). Higher values result in smaller files but slower encoding.
  • optimize: Applies additional optimization algorithms to reduce file size.

WebP Options

  • quality: Controls compression level for lossy WebP (1-100).
  • lossless: Uses lossless compression instead of lossy, preserving all details but resulting in larger files.

General Options

  • strip_metadata: Removes EXIF data, color profiles, and other metadata to reduce file size.
  • optimize: Applies format-specific optimizations to reduce file size.

Error Responses

Status CodeDescription
400Bad request. Missing required parameters, invalid format value, invalid quality value, invalid compression_level, invalid boolean parameters, or unsupported input file format.
413Payload too large. The file size exceeds the maximum allowed limit.
415Unsupported media type. The input file is not a valid image or is in an unsupported format.
500Internal server error. Something went wrong on the server.

Notes

  • When converting from a format with transparency (PNG, WebP) to a format without transparency (JPEG), transparent areas will be filled with a white background by default.
  • Converting from a higher bit depth to a lower one (e.g., 16-bit TIFF to 8-bit PNG) may result in some loss of color information.
  • GIF to GIF conversion preserves animation if the input is an animated GIF.
  • Converting to WebP is recommended for web use as it typically provides the best balance of quality and file size.
  • The strip_metadata option is useful for privacy (removing location data) and for reducing file size.
  • Progressive JPEGs are useful for web pages as they allow the image to be displayed gradually as it loads.
  • The maximum file size allowed is 50MB.
  • For the best quality when converting from lossy formats (JPEG), consider using a high quality setting to minimize additional quality loss.

Use Cases

  • Converting images to WebP for better web performance
  • Converting transparent PNGs to JPEGs with a white background for printing
  • Converting high-quality TIFF images to web-friendly formats
  • Converting between formats for compatibility with specific applications
  • Optimizing images for different use cases (web, print, storage)
  • Removing metadata for privacy or file size reduction
  • Converting HEIC photos from iOS devices to more widely supported formats
  • Creating progressive JPEGs for better perceived loading performance on websites