ForHosting KIT · Images

Resize image canvas with padding

Resize an image canvas with padding when the picture itself must stay at its original pixel dimensions.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

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

Supply the image width and height, the larger target canvas dimensions, and the background color you plan to use. The calculator returns the exact padding for every side and the image's top-left position on the new canvas. It never crops, stretches, or resamples the source. If either target dimension is too small to contain the image, the request fails instead of silently changing the artwork.

Expand the canvas while preserving every source pixel

Canvas resizing and image scaling solve different problems. Scaling changes the number of pixels occupied by the picture, which can soften details, alter carefully prepared dimensions, or violate a production requirement. This calculator leaves the image width and height untouched. It subtracts those dimensions from the requested canvas, then describes the empty area that must be added around the source. That makes it useful when a product photo, illustration, screenshot, or generated asset is already the correct size but needs a larger frame. Enter positive integer dimensions in pixels and provide the background color that the eventual image operation should use. The result repeats the image and canvas dimensions, reports top, right, bottom, and left padding, and gives the x and y coordinates where the image begins. No image file is uploaded or decoded because the calculation depends only on geometry. The background color is returned as a trimmed label so downstream code can carry the chosen fill alongside the measurements.

Understand centering when the spare pixels are uneven

Perfect centering is straightforward when the difference between canvas and image dimensions is even. For example, adding 400 horizontal pixels produces 200 pixels on both the left and right. An odd difference cannot be split into two whole-pixel halves. In that case, this calculator places the smaller share on the left or top and the extra pixel on the right or bottom. A horizontal difference of 401 therefore becomes 200 pixels left and 201 pixels right. This convention keeps the image position deterministic and avoids fractional coordinates that raster tools cannot represent. The returned image_position is the same as the left and top padding, so it can be passed directly to many drawing, compositing, or command-line image APIs. Adding left, image width, and right always reproduces the canvas width; the equivalent vertical sum always reproduces the canvas height. These invariants make the response easy to validate in an automated workflow before any real image processing begins.

Validate the target before building an image workflow

The target canvas must be at least as wide and at least as tall as the source image. Meeting only one condition is not enough: a wide but short canvas would still crop vertically, while a tall but narrow canvas would crop horizontally. The calculator rejects either case with an invalid-input error, making an accidental crop visible at the planning stage. Equal dimensions are valid and return zero padding on all four sides, which is helpful when a pipeline accepts mixed inputs and some assets already match the target. The background color is intentionally treated as a non-empty string rather than interpreted as one particular color syntax. You can carry a hexadecimal color, a CSS-style value, a named color, or a workflow-specific token such as transparent, provided the image processor used later understands it. Use the response to configure a canvas-extend operation in your preferred library or service. The API costs $0.002 per request, and its deterministic arithmetic makes repeated inputs produce identical output.

Standardize product photo canvases

Center an already sized product image on a uniform catalog canvas without enlarging or cropping the product.

Prepare social graphics safely

Calculate the border required around finished artwork before exporting it into a larger platform-specific canvas.

Configure an image pipeline

Turn source and target dimensions into exact offsets for a later canvas-extension operation in an image library.

Does this resize or resample the image?

No. It preserves the supplied image dimensions and only calculates the extra canvas area around it.

What happens when the target canvas is smaller?

The request returns an invalid-input error if either target dimension is smaller than the corresponding image dimension.

Where does an extra pixel go when padding is odd?

The extra pixel is assigned to the right or bottom; the left and top use the lower whole-pixel half.

Which background color formats are supported?

The calculator accepts any non-empty color string and returns it trimmed. Your downstream image tool determines whether that syntax is valid.

How much does an API request cost?

Each API request costs $0.002. The calculation uses only the dimensions and color text, not the image file itself.

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/canvas-resize-pad

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/canvas-resize-pad \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image_width":1200,"image_height":800,"canvas_width":1600,"canvas_height":1000,"background_color":"#ffffff"}'
{
  "image_width": 1200,
  "image_height": 800,
  "canvas_width": 1600,
  "canvas_height": 1000,
  "background_color": "#ffffff"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "image.canvas_resize_pad",
  "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 →