Staaarter

JPG Margin Adder

Uploads a JPG and expands its canvas by independent margin amounts on each of the four sides (top, right, bottom, and left can each be different), filling the new space with a solid background color, then downloads the result as a JPG. Similar to a CSS margin, but for the image canvas itself. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-29
By Staaarter Team
editormarginspacingcanvasjpg

Overview

Introduction

This tool expands a JPG's canvas by independent margin amounts on each of the four sides, entirely client-side.

It's the asymmetric sibling of JPG Border Adder: use it whenever you need different spacing on different sides rather than a uniform frame.

What Is JPG Margin Adder?

A client-side per-side canvas-expansion tool: you specify a top, right, bottom, and left margin (any of which can be 0 or a different value from the others), pick a fill color, and the tool builds a larger canvas with the original photo placed at the correct offset.

It's conceptually the same idea as a CSS `margin` shorthand, but it physically grows the image file rather than just shifting layout.

How JPG Margin Adder Works

The tool computes the new canvas width as the original width plus the left and right margins, and the new height as the original height plus the top and bottom margins, fills the entire new canvas with the chosen color, then copies the original photo's pixels in at an offset of (left, top).

Each margin value is validated independently as a non-negative whole number before any drawing happens.

When To Use JPG Margin Adder

Use it to add extra space above and below a photo for a caption area, extra space to one side for a sidebar layout, or to match an asymmetric spacing spec from a design system.

If you just need the same spacing on all four sides, JPG Border Adder or JPG Padding Adder are simpler options.

Features

Advantages

  • Runs entirely client-side.
  • Full independent control over all four sides in one pass.
  • Same underlying canvas-expand-and-fill approach as the border/padding tools, just generalized to per-side amounts.

Limitations

  • Requires four separate inputs instead of one uniform value, which is more setup for the common symmetric case.
  • Very large asymmetric margins on an already-large photo can hit the site's 4096px maximum dimension.

Examples

Add space above and below for a caption

Input

A 1000x600 JPG, top 80, bottom 80, left 0, right 0, white

Output

A 1000x760 JPG with white bands above and below the photo

Common when preparing a photo for a caption or credit line layout.

Add asymmetric spacing for a sidebar layout

Input

A 900x900 JPG, top 0, right 300, bottom 0, left 0, light gray

Output

A 1200x900 JPG with a gray sidebar area to the right

Useful when placing text or a logo alongside the photo.

Best Practices & Notes

Best Practices

  • Use 0 for any side you don't want to change rather than guessing a small nonzero value.
  • Pick a fill color that matches your intended layout background so the seam between photo and margin isn't visually jarring.

Developer Notes

addJpgMargin validates all four margin values independently, computes the expanded canvas size from (left+right) and (top+bottom), fills it with the chosen opaque color, then copies the source pixels in at the (left, top) offset; distinct math from addJpgBorder's single-thickness expansion, since each side can differ.

JPG Margin Adder Use Cases

  • Adding caption space above/below a photo
  • Creating asymmetric spacing for a sidebar-style layout
  • Matching a design system's non-uniform spacing spec

Common Mistakes

  • Leaving all four margins at 0, which the tool rejects since nothing would change.
  • Expecting per-side control from JPG Border Adder; that tool is uniform-only by design.

Tips

  • For the common case of equal spacing on all sides, JPG Border Adder or JPG Padding Adder require only one input instead of four.
  • Use JPG Margin Remover afterward with the same values to undo the change exactly.

References

Frequently Asked Questions