Oyyi

Draw Rectangle

Draw a customizable rectangle on an image with control over position, color, thickness, and fill.

POST /api/image/draw-rectangle

Request Parameters

Parameter Type Required Description
file File Yes The image file to process. Supported formats: JPEG, PNG, WebP, BMP, TIFF.
x1 Integer Yes The x-coordinate of the top-left corner of the rectangle.
y1 Integer Yes The y-coordinate of the top-left corner of the rectangle.
x2 Integer Yes The x-coordinate of the bottom-right corner of the rectangle.
y2 Integer Yes The y-coordinate of the bottom-right corner of the rectangle.
color String No The color of the rectangle. Can be a color name (e.g., red, blue) or a hex code (e.g., #FF0000). Default: red.
thickness Integer No The thickness of the rectangle border in pixels. Range: 1-20. Default: 2.
radius Integer No The radius of the rounded corners in pixels. Only used if rounded is true. Range: 1-50. Default: 10.

Response

Returns the image with the rectangle drawn on it, in the same format as the input file.

Example Request

    // example.sh
curl -X POST "https://oyyi.xyz/api/image/draw-rectangle"   -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@image.jpg" \
  -F "x1=100" \
  -F "y1=100" \
  -F "x2=400" \
  -F "y2=300" \
  -F "color=red" \
  -F "thickness=2" \
  --output rectangle.jpg
  

Example with Python

    // draw_rectangle.py
import requests

url = "https://oyyi.xyz/api/image/draw-rectangle"

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

data = {
    'x1': 100,
    'y1': 100,
    'x2': 400,
    'y2': 300,
    'color': 'red',
    'thickness': 3
}

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

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

Example with JavaScript

    // draw_rectangle.js
// Using fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('x1', '100');
formData.append('y1', '100');
formData.append('x2', '400');
formData.append('y2', '300');
formData.append('color', 'red');
formData.append('thickness', '3');

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

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

Rectangle Styles

Outline

Standard rectangle with only the border drawn. Good for highlighting areas without obscuring content.

Filled

Rectangle filled with the specified color. Good for masking or emphasizing areas. Use with opacity < 1.0 to see through.

Rounded

Rectangle with rounded corners. Creates a softer, more modern look.

Semi-Transparent

Rectangle with reduced opacity. Good for highlighting areas while still showing the content underneath.

How It Works

The draw-rectangle endpoint adds a customizable rectangle to an image:

  1. Coordinate Calculation: The rectangle is defined by its top-left (x1, y1) and bottom-right (x2, y2) coordinates.
  2. Color Processing: The specified color is parsed from a name or hex code.
  3. Opacity Adjustment: If opacity is less than 1.0, the color is made semi-transparent.
  4. Drawing: The rectangle is drawn on the image with the specified thickness.
  5. Filling (Optional): If fill is true, the rectangle is filled with the specified color.
  6. Rounding (Optional): If rounded is true, the corners are rounded with the specified radius.

The result is an image with a customized rectangle that can be used for highlighting, annotation, or masking purposes.

Common Use Cases

Highlighting

Use a thin, bright-colored outline to draw attention to specific areas of an image.

Censoring

Use a filled, opaque rectangle to cover sensitive information in images.

Annotation

Use rectangles to mark objects or regions of interest in images for analysis or documentation.

UI Mockups

Use rounded, semi-transparent rectangles to simulate UI elements or buttons on screenshots.

Error Responses

Status Code Description
400 Bad request. Missing required parameters, invalid coordinates, invalid color, invalid thickness, invalid opacity, invalid radius, 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

  • Coordinates (0, 0) represent the top-left corner of the image.
  • If the specified coordinates are outside the image boundaries, the rectangle will be clipped to fit within the image.
  • For a square, set the width and height to be equal (i.e., x2 - x1 = y2 - y1).
  • For a filled rectangle with some transparency, set fill to true and opacity to a value less than 1.0.
  • The maximum file size allowed is 10MB.
  • This operation preserves the alpha channel (transparency) if present in the original image.
  • For multiple rectangles, make separate API calls for each rectangle.

Use Cases

  • Highlighting areas of interest in screenshots or diagrams
  • Creating bounding boxes for object detection or recognition
  • Censoring or redacting sensitive information in images
  • Marking regions for cropping or further processing
  • Creating simple annotations or markups on images
  • Designing UI mockups or wireframes
  • Adding colored backgrounds for text or other elements