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.
decimalRatiois rounded to 3 decimal places.
Endpoints
POST
https://opentools.ca/api/v1/tools/aspect-ratio-calculatorCalculate a missing dimension, simplify a ratio, or get the ratio of a width and height
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| action | string Enum: calculate, simplify, fromDimensions | Optional | What to do. calculate needs ratioX, ratioY, dimension and dimensionType; simplify and fromDimensions need width and height.Default: calculate |
| ratioX | number | Optional | Width part of the ratio, e.g. 16 for 16:9. Required for calculate. |
| ratioY | number | Optional | Height part of the ratio, e.g. 9 for 16:9. Required for calculate. |
| dimension | number | Optional | The known side, in any unit (usually pixels). Required for calculate. |
| dimensionType | string Enum: width, height | Optional | Which side dimension is. Required for calculate. |
| width | number | Optional | Width. Required for simplify and fromDimensions. |
| height | number | Optional | Height. 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 key403
API key is deactivated or expired, or this IP address is not allowed for the key429
Rate limit exceeded (120 requests per minute per key)500
Internal server errorCode 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}'Rather use it in your browser? Open the Aspect Ratio Calculator
