Oyyi

Apply Grayscale

Convert images to grayscale using Numba-optimized pixel operations for superior performance.

POST /api/image/grayscale

Request Parameters

ParameterTypeRequiredDescription
fileFileYesThe image file to convert to grayscale. Supported formats: JPEG, PNG, WebP, BMP, TIFF.

Response

Returns the grayscale image in the same format as the input file.

Example Request

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

Example with Python

    // grayscale.py
import requests

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

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

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

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

Example with JavaScript

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

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

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

How It Works

The grayscale conversion process transforms a color image into one where each pixel has the same value for its red, green, and blue components, creating a shade of gray.

Error Responses

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

Notes

  • The implementation is optimized with Numba for high-performance processing.
  • The maximum file size allowed is 10MB.
  • Alpha channels (transparency) in PNG and WebP images are preserved.
  • Grayscale images typically have smaller file sizes than color images when saved in formats like JPEG.

Use Cases

  • Creating classic black and white photography effects
  • Reducing visual complexity to focus on form and composition
  • Preparing images for print in non-color publications
  • Creating base images for further processing (e.g., edge detection, thresholding)
  • Reducing file size for storage or transmission
  • Creating artistic effects or vintage looks

Performance

Our grayscale conversion is highly optimized and can process a 1080p image in approximately 38ms, making it suitable for real-time applications.