Aspect Ratio Calculator

Aspect Ratio Calculator API

Web Development

Calculate aspect ratios for images and videos.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

120 requests per minute

Endpoints

1 endpoint available

Overview

Work with aspect ratios. One endpoint, three actions:

  • calculate (default): give a ratio (ratioX:ratioY) and one known side, get the other side. The calculated side is rounded to the nearest whole number.
  • simplify: reduce a width and height to the smallest whole-number ratio (1920 x 1080 gives 16:9).
  • fromDimensions: like simplify, but also returns the decimal ratio (width / height).

Notes

  • All numbers must be greater than 0 and at most 1,000,000. Decimals are allowed (e.g. 2.35:1).
  • Decimal inputs to simplify and fromDimensions are scaled by 1000 before reducing, so 2.35 x 1 gives 47:20.
  • decimalRatio is rounded to 3 decimal places.

Endpoints

POST
https://opentools.ca/api/v1/tools/aspect-ratio-calculator
Calculate a missing dimension, simplify a ratio, or get the ratio of a width and height

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
action
string
Enum: calculate, simplify, fromDimensions
OptionalWhat to do. calculate needs ratioX, ratioY, dimension and dimensionType; simplify and fromDimensions need width and height.Default: calculate
ratioX
number
OptionalWidth part of the ratio, e.g. 16 for 16:9. Required for calculate.
ratioY
number
OptionalHeight part of the ratio, e.g. 9 for 16:9. Required for calculate.
dimension
number
OptionalThe known side, in any unit (usually pixels). Required for calculate.
dimensionType
string
Enum: width, height
OptionalWhich side dimension is. Required for calculate.
width
number
OptionalWidth. Required for simplify and fromDimensions.
height
number
OptionalHeight. Required for simplify and fromDimensions.

Response Example

// action: "calculate" (or "fromDimensions")
{
  "success": true,
  "width": 1920,
  "height": 1080,
  "ratio": "16:9",
  "decimalRatio": 1.778
}

// action: "simplify"
{
  "success": true,
  "originalWidth": 1920,
  "originalHeight": 1080,
  "ratio": "16:9",
  "ratioX": 16,
  "ratioY": 9
}

Error Codes

400
Invalid request. Validation problems are listed in details.
401
Missing or invalid API key
403
API key is deactivated or expired, or this IP address is not allowed for the key
429
Rate limit exceeded (120 requests per minute per key)
500
Internal server error

Code Examples

# Height for a 16:9 image that is 1920 wide
curl -X POST https://opentools.ca/api/v1/tools/aspect-ratio-calculator   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"action": "calculate", "ratioX": 16, "ratioY": 9, "dimension": 1920, "dimensionType": "width"}'

# Simplify 1920 x 1080
curl -X POST https://opentools.ca/api/v1/tools/aspect-ratio-calculator   -H "Authorization: Bearer YOUR_API_KEY"   -H "Content-Type: application/json"   -d '{"action": "simplify", "width": 1920, "height": 1080}'

Ready to get started?

Create an API key to start using the Aspect Ratio Calculator API.

Rather use it in your browser? Open the Aspect Ratio Calculator