Add Border to Bitmap
Add customizable borders to bitmap images online. Set width, color, style, radius and export PNG/JPEG. Free browser-based tool.
About
Adding a border to a bitmap image is a pixel-level operation. The tool composites a new canvas of dimensions W + 2b by H + 2b, where b is the border width in pixels, then draws the source image at offset (b, b). Incorrect border application in batch workflows causes misaligned sprites, broken tiling, and print bleed errors. This tool operates entirely in the browser using the Canvas API at full source resolution. No server upload. No compression artifacts from re-encoding. It supports solid, dashed, dotted, double, and gradient border styles with optional corner radius. Output is lossless PNG or configurable-quality JPEG.
Limitations: very large bitmaps (above 8000ร8000 px) may hit browser canvas memory limits on mobile devices. The border is rasterized into the output. It is not metadata or a vector layer. For print work, convert border width from mm to px using your target DPI: px = mm ร DPI รท 25.4.
Formulas
The output canvas dimensions are computed from the source image and border width:
Where Wsrc and Hsrc are original image dimensions in pixels, and b is border width in pixels. The image is drawn at canvas position (b, b).
For print-to-pixel conversion:
Where bmm is desired border width in millimeters, DPI is target print resolution (typically 300), and 25.4 is millimeters per inch.
For rounded corners, the corner radius r is clamped:
This prevents the radius from exceeding half the shorter dimension, which would produce rendering artifacts.
Reference Data
| Border Style | Description | Use Case | Canvas Method |
|---|---|---|---|
| Solid | Uniform color fill around image | General framing, print margins | fillRect() |
| Dashed | Repeating dash pattern | Draft/proof marks, design mockups | setLineDash([12,6]) |
| Dotted | Repeating dot pattern | Decorative frames, UI thumbnails | setLineDash([2,4]) |
| Double | Two parallel lines with gap | Certificate borders, formal documents | Two strokeRect() calls |
| Gradient | Color transition from outer to inner edge | Social media posts, creative framing | createLinearGradient() |
| Rounded Solid | Solid with rounded corners via arcTo() | App icons, profile pictures | clip() + arcTo() |
| Format | Extension | Compression | Alpha Channel | Max Canvas Size (typical) |
|---|---|---|---|---|
| PNG | .png | Lossless | Yes | 16384ร16384 px |
| JPEG | .jpg | Lossy (quality 0 - 1) | No | 16384ร16384 px |
| WebP | .webp | Lossy/Lossless | Yes | 16383ร16383 px |
| Print DPI | 1 mm in px | 5 mm border | 10 mm border | 25 mm border |
|---|---|---|---|---|
| 72 | 2.83 | 14 px | 28 px | 71 px |
| 150 | 5.91 | 30 px | 59 px | 148 px |
| 300 | 11.81 | 59 px | 118 px | 295 px |
| 600 | 23.62 | 118 px | 236 px | 591 px |