apyhub
FILE MANIPULATION

Change Image Aspect Ratio API

What it does

Image Aspect Ratio Restore takes a stretched image and returns a binary image adjusted to a target aspect ratio. Send a single image file in the request body, and optionally set target_aspect in the query string to values like 4:3 or use the default 1:1.

Use keep_long_edge when you want to preserve the longer side of the image while restoring proportions. The service is designed for cases where an image has been displayed or resized incorrectly and needs to be brought back into a standard layout for further editing, publishing, or storage.

The response is the corrected image as binary data, so you can pass it straight into your next image workflow without parsing extra metadata. That makes it useful in automated asset pipelines, CMS cleanup jobs, or any process that needs to normalize user-uploaded images before delivery.

POST
Restore a stretched image to a target aspect ratio
https://api.eu.apyhub.com/dosvak/restore-image-aspect-ratio

QUICKSTART

GUIDE

Quickstart

Restore an image while keeping its aspect ratio by uploading a file and choosing the target ratio as a query parameter.

curl -X POST "https://api.eu.apyhub.com/dosvak/restore-image-aspect-ratio?target_aspect=4%3A3" \
  -H "apy-token: $APY_TOKEN" \
  -F "file=@/path/to/image.jpg"

What you'll get back

Returns a binary file (string with format: binary), which is the restored image.

TRY ITLIVE · 100 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.
body*
Image file

About this endpoint

What it does

Restores a stretched image to a target aspect ratio by accepting an uploaded image file and returning the processed image as binary data.

Query Parameter(s)

AttributeTypeMandatoryDescription
target_aspectStringNoTarget aspect ratio for the restored image. Must match the pattern ^\d+(\.\d+)?:\d+(\.\d+)?$. Default: 1:1.
keep_long_edgeBooleanNoWhether to keep the long edge while restoring the image. Default: true.

Request Body

ParameterTypeMandatoryDescription
fileStringYesImage file, binary format. Maximum size: 20 MB.

Response

Returns a binary file containing the restored image. The success response is a raw binary payload, not a JSON object.

Query parameters

Name
Type
Description
target_aspectOPTIONAL
string
DEFAULT 1:1
keep_long_edgeOPTIONAL
boolean
DEFAULT true

Body

Name
Type
Description
bodyREQUIRED
object

Max 100MB total per request (all files combined). Larger? Use this API's URL-based endpoint instead, if it has one.

▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.