ForHosting KIT · Images

Crop image to box

Crop image to box calculations look simple until an automated job receives coordinates that extend one pixel beyond the source.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Runs in your browser. Free, unlimited — your data never leaves this page.

This validator accepts the source image width and height together with an explicit crop box described by x, y, width, and height. It checks every value, confirms that the complete rectangle stays inside the image, and returns the cropped dimensions when the box is valid. No image upload or decoding is required, so it is useful before invoking an image processor, building a crop preview, or accepting crop coordinates from another service.

Describe the source image and crop box

Start with the source image dimensions in pixels. Set image_width to the full horizontal pixel count and image_height to the full vertical pixel count. Then describe the crop rectangle with x, y, width, and height. The x and y values locate the rectangle's top-left corner relative to the image's top-left corner, which is coordinate 0,0. Width extends to the right and height extends downward. All six values must be integers because the capability models pixel-aligned raster cropping rather than fractional geometry. Image and crop dimensions must be positive, while x and y may be zero. For example, an x value of 240 skips the first 240 pixel columns before the crop begins. A box may touch any image edge exactly. Thus, x plus width may equal image_width, and y plus height may equal image_height. Supply the dimensions reported by the same image asset that will later be cropped; coordinates from a resized preview will not describe the original unless they have first been scaled.

Understand how boundary validation works

The validator first rejects missing values, non-integers, negative coordinates, zero-sized boxes, and values outside the documented numeric range. It then checks the two boundaries that define containment. Horizontally, x plus width must be less than or equal to image_width. Vertically, y plus height must be less than or equal to image_height. If either sum is larger, part of the requested crop lies outside the source and the request returns an invalid input error. This explicit containment rule avoids a common off-by-one misunderstanding: a 100-pixel-wide crop beginning at x 0 occupies columns from the left edge through the complete 100-pixel span, so it fits a 100-pixel-wide image exactly. The capability does not clamp, shift, or shrink an invalid box because silently changing user coordinates can produce the wrong subject or composition. It also does not inspect image bytes. Its decision is determined solely by the dimensions and coordinates supplied, making the result fast, repeatable, and suitable for validation in both interactive forms and automated pipelines.

Use the result before an actual crop operation

A successful response returns the width and height of the resulting crop. Those values match the requested box because this capability validates geometry; it does not resample or alter the rectangle. Use the response as a guard before passing the same coordinates to an image manipulation library, a media service, or a queued rendering job. This separates inexpensive input validation from more expensive image decoding and prevents predictable boundary failures from reaching downstream workers. In a crop editor, validate after the user confirms a selection or after preview coordinates have been converted back to original-image pixels. In a data pipeline, validate crop metadata as soon as it arrives and route invalid records for correction. Keep orientation in mind: if another step physically rotates an image, use the dimensions after that rotation and coordinates expressed in the same orientation. The API request costs $0.002; the browser runner can perform the same deterministic calculation locally. Neither path uploads an image because only numeric geometry is needed for the answer.

Guard an image processing queue

Reject out-of-bounds crop metadata before a worker downloads and decodes the source image.

Validate a crop editor selection

Confirm that pixel coordinates converted from a preview still fit the original image dimensions.

Check imported media metadata

Audit stored crop rectangles and identify records that cannot be applied to their associated assets.

Does this capability crop or upload the image?

No. It validates numeric dimensions and coordinates only, then returns the dimensions the crop would have.

Can a crop box touch the right or bottom edge?

Yes. A box is valid when x plus width equals image_width or y plus height equals image_height.

Are fractional coordinates supported?

No. All dimensions and coordinates must be integers so the box is aligned to raster pixels.

Will an out-of-bounds box be clamped automatically?

No. The request returns an invalid input error instead of changing the requested crop.

What does an API request cost?

Each API request costs $0.002. The same deterministic validation is also available in the browser runner.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/image/crop-to-box

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/image/crop-to-box \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image_width":1920,"image_height":1080,"x":240,"y":120,"width":800,"height":600}'
{
  "image_width": 1920,
  "image_height": 1080,
  "x": 240,
  "y": 120,
  "width": 800,
  "height": 600
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "image.crop_to_box",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_mb15
max_megapixels12
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →