Oyyi

Enhance Contrast

Enhance the contrast of an image to make details more visible and create more visual impact.

POST /api/image/contrast

Request Parameters

Parameter Type Required Description
file File Yes The image file to enhance. Supported formats: JPEG, PNG, WebP, BMP, TIFF.
factor Float No The contrast enhancement factor. Values > 1.0 increase contrast, values < 1.0 decrease contrast. Range: 0.1-5.0. Default: 1.5.

Response

Returns the contrast-enhanced image in the same format as the input file.

Example Request

    curl -X POST "https://oyyi.xyz/api/image/contrast"   -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@image.jpg" \
  -F "factor=1.5" \
  --output enhanced.jpg
  

Example with Python

    import requests

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

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

data = {
    'factor': 1.5
}

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

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

Example with JavaScript

    // Using fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('factor', '1.5');

fetch('https://oyyi.xyz/api/image/contrast', {
  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 = 'enhanced.jpg';
  a.click();

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

Contrast Factor Examples

Low Factor (0.1-0.9)

Reduces contrast, creates a flatter look

Normal Factor (1.0)

No change to contrast

High Factor (1.5-5.0)

Increases contrast, makes darks darker and lights lighter

How It Works

Contrast enhancement works by increasing the difference between light and dark areas in an image:

  • For each pixel, the difference from the middle gray value (128) is multiplied by the contrast factor. This stretches the histogram around the middle point.

Error Responses

Status Code Description
400 Bad request. Missing required parameters, invalid factor value, invalid method, or invalid file format.
413 Payload too large. The file size exceeds the maximum allowed limit.
500 Internal server error. Something went wrong on the server.

Notes

  • Very high contrast factors may result in loss of detail in very dark or very bright areas.
  • For subtle enhancement, use values between 1.1 and 1.5.
  • For dramatic enhancement, use values between 2.0 and 5.0.
  • To reduce contrast (for a more muted look), use values between 0.1 and 0.9.
  • The maximum file size allowed is 10MB.
  • This operation preserves the alpha channel (transparency) if present in the original image.

Use Cases

  • Enhancing details in flat or hazy images
  • Creating more dramatic or punchy images
  • Improving visibility of text or graphics
  • Preparing images for print where higher contrast is often needed
  • Creating artistic effects with extreme contrast settings
  • Improving the readability of scanned documents