apyhub
Back

Crop Image to Desired Size API

What it does

Image Cropper lets you crop an image by sending the source file and crop bounds, then returns the cropped image as binary output. Use it when you need to trim user-uploaded photos, isolate a product shot, or generate fixed image regions for downstream processing.

POST /image-crop with an image file up to 15 MB and the crop rectangle defined by x, y, w, and h in pixels. You can also specify format as png or jpeg to control the output image type. The service does not return metadata or a JSON wrapper; it returns the cropped image directly.

This is a good fit for image pipelines where you already know the target region, such as avatar creation, thumbnail preparation, document image cleanup, or extracting a specific area from a screenshot. The API keeps the interaction simple: define the crop area, send the file, and use the returned image wherever your app needs it.

POST
Crop an image
https://api.eu.apyhub.com/freedailypro/crop-image-to-desired-size-api/image-crop

QUICKSTART

GUIDE

Quickstart

Crop an uploaded image by sending the file and the crop region as fractions (0–1) of the image size.

curl -X POST "https://api.eu.apyhub.com/freedailypro/crop-image-to-desired-size-api/image-crop" \
  -H "apy-token: $APY_TOKEN" \
  -F "file=@/path/to/image.jpg" \
  -F "x=0.1" \
  -F "y=0.1" \
  -F "w=0.5" \
  -F "h=0.5"

What you'll get back

Returns the cropped image as binary data (a file download), not a JSON object. The example above crops the area starting 10% from the left and top edges and covering 50% of the width and height.

TRY ITLIVE · 10 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*
Height of the crop area (0–1, relative to image height).
Width of the crop area (0–1, relative to image width).
Horizontal starting position of the crop (0–1, relative to image width).
Vertical starting position of the crop (0–1, relative to image height).
The image. Up to 15 MB.
png or jpeg

About this endpoint

What it does

Crops an uploaded image to a rectangular region and returns the cropped image as binary data. The region is given as fractions of the image size, so the same values work for any resolution.

Request Body

ParameterTypeMandatoryDescription
fileStringYesThe image file to crop. Binary upload. Up to 15 MB.
xNumberYesHorizontal starting position of the crop (0–1, relative to image width).
yNumberYesVertical starting position of the crop (0–1, relative to image height).
wNumberYesWidth of the crop area (0–1, relative to image width).
hNumberYesHeight of the crop area (0–1, relative to image height).
formatStringNoOutput image format: png or jpeg.

Example: x = 0.1, y = 0.1, w = 0.5, h = 0.5 defines a crop area starting 10% from the left and top edges, covering 50% of the image's width and height.

Response

Returns a binary file containing the cropped image. The response body is a single binary string, not a JSON 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.