Skip to content

Image Processing ​

Welcome to the Image Processing API documentation! This API allows you to perform various transformations on images, such as rotation, cropping, grayscale conversion, flipping, and compression.

Supported Features ​

Rotation ​

Rotate an image by a specified angle.

Cropping ​

Crop a specific area of the image.

Grayscale Conversion ​

Convert an image to grayscale.

Flipping ​

Flip an image horizontally or vertically.

Compression ​

Reduce the size of the image by adjusting its width, height, and quality.

API Endpoint ​

/process ​

This is the main endpoint for processing images.

Header Parameters ​

X-RapidAPI-Key (Required) ​

Your Rapid API Key, Used to authenticate and manange your subscription

Body Parameters ​

image (Required) ​

The image file to be processed.

rotate (Optional) ​

The angle to rotate the image by (in degrees).

crop (Optional) ​

An object containing the crop details.

  • width: The width of the cropped area.
  • height: The height of the cropped area.
  • left: The left offset of the cropped area.
  • top: The top offset of the cropped area.

grayscale (Optional) ​

Whether to convert the image to grayscale (boolean).

flip (Optional) ​

The direction to flip the image (horizontal, horizontalReverse, vertical, verticalReverse).

compress (Optional) ​

An object containing the compression parameters.

  • width: (Optional) The desired width of the compressed image.
  • height: (Optional) The desired height of the compressed image.
  • quality: (Optional) The image quality (0-100).
  • format: (Optional) The desired image format (jpg, png).

Response ​

If successful, the API returns the processed image in the requested format. If there are any errors, the API returns an error message in JSON format.

Error Codes ​

  • 400: Bad request.
  • 500: Internal server error.

Example Usage ​

cURL Example ​

bash
curl -X POST https://your-api-endpoint/process \
--form image=@path/to/image.jpg \
--form rotate=90
-H "X-RapidAPI-Key: Your-RapidAPI-Key"

Replace Your-RapidAPI-Key with the actual key provided by RapidAPI.

This request will rotate the image image.jpg by 90 degrees and return the processed image.

Node.js Example ​

javascript
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');

const apiUrl = 'https://your-api-endpoint/process';
const rapidAPIKey = 'Your-RapidAPI-Key';

const formData = new FormData();
formData.append('image', fs.createReadStream('path/to/image.jpg'));
formData.append('rotate', 90);

axios.post(apiUrl, formData, {
  headers: {
    ...formData.getHeaders(),
    'X-RapidAPI-Key': rapidAPIKey,
  },
})
  .then(response => {
    // Process the response
    console.log(response.data);
  })
  .catch(error => {
    // Handle errors
    console.error(error.response.data);
  });

Again, replace Your-RapidAPI-Key with the actual key provided by RapidAPI.

Including the X-RapidAPI key in the headers is crucial for authentication and authorization when making requests to the API. Make sure to keep your API key secure and do not expose it publicly.

This Node.js example demonstrates how to use the API to rotate an image by 90 degrees.

Additional Notes ​

  • The maximum image size supported is 6 MB.
  • The default image format used for compression is png.
  • See the documentation for the sharp library for more information on supported image formats and transformation options.

Released under the MIT License.