Extend the borders of card scans for printing — continues the existing border pattern without re-encoding the original image data
Project description
cardbleed
Extends the borders of card scans so a printed and cut card doesn't end up with a border that is too thin. The extension continues whatever border the card already has (holofoil speckle, solid colors, gradients), and the original image data is never re-encoded: PNG and WebP pixels stay bit-identical, and JPEGs are extended by splicing DCT coefficient blocks around the untouched originals.
input, 400×550 |
output, cardbleed demo_card.png -e 24 |
The demo card is generated by a script (examples/make_demo.py), so the repository contains no copyrighted scans. It has the traits that make real scans annoying: a speckled border, a brightness gradient across it, a scanner-bloom line at the very edge, and an inner frame line. Bloom is trimmed and the frame line is detected automatically, so sampling never crosses into it.
Install
uv tool install cardbleed # or: pipx install cardbleed
uvx cardbleed card.png # or run once without installing
Until the first PyPI release, install from GitHub instead:
uv tool install git+https://github.com/ErikBavenstrand/cardbleed
Usage
cardbleed card.png --compare # extend 16px, write a comparison sheet
cardbleed ./cards/ -e 2.5mm --recursive # batch a folder, mm-based sizing
cardbleed card.jpg -e 20 --fix-aspect # pad to the 63x88 ratio, then extend
cardbleed card.png --target 69x94mm # pad to an exact final size
Outputs are written next to the input (or to --out-dir) with an _ext
suffix. Inputs are never overwritten. --compare also writes a side-by-side
sheet with the original boundary marked, which makes it easy to check the
seam.
Modes
Zoomed left-edge detail, one panel per setting: smart, pattern, naive, mirror, soft.
--mode pattern(default) keeps structure intact: every output line is a real contiguous border line, and each outward pass is shifted along the edge by a random offset. If the border has a repeating pattern, detected by autocorrelation, the continuation and the offsets snap to its period so the pattern stays in phase. With--shuffle 0it degrades to a plain deterministic mirror.--mode smartresamples the border band stochastically. Speckle is re-randomized in both directions, so nothing streaks or repeats, at the cost of some texture structure.--mode naivereplicates the outermost line straight outward (plus noise and smudge). Mostly useful as a baseline; it streaks on textured borders.
The gallery variants above, for reference:
--mode smart |
--mode naive |
--smudge 2.5 --noise 0.8 |
--compare sheet |
Format handling
| Format | What happens to the original data |
|---|---|
| PNG | re-serialized losslessly; pixels bit-identical |
| WebP | written as lossless WebP; decoded pixels preserved exactly |
| JPEG | original quantized DCT blocks are copied bit-exact into a larger coefficient grid; only the new border blocks are encoded, using the file's own quantization tables |
For JPEG the extension amounts have to align to the MCU grid (8 or 16 px). The remainder is shifted between opposite edges, so the final dimensions are still exactly what you asked for.
Options
cardbleed --help has the full reference. The ones worth knowing:
| Flag | Default | Meaning |
|---|---|---|
-e, --extend |
16 |
Amount per edge, px or mm (2.5mm); per-edge overrides via --left etc. |
--fix-aspect |
off | Pad the short axis to the card ratio (--card-size, default 63x88 mm) before extending |
--target |
none | Pad to an exact final size instead, e.g. 69x94mm |
--mode |
pattern |
pattern, smart, or naive (see above) |
-k, --sample |
12 |
Band depth to sample from; clamped at detected inner border structure |
--trim |
auto |
Scanner-bloom lines to cut per edge |
--shuffle |
48 |
How far along the edge texture may be borrowed from |
--noise, --smudge |
0.35, 0.6 |
Added grain (relative to the border's own) and ramped blur |
--seed |
0 |
Output is deterministic per file |
How it works
Each edge is analyzed on the original image: bloom lines are trimmed and the sampling band is clamped before inner border structure. The border is split into a smooth tone component, which is continued outward mirrored so gradients stay seam-continuous, and a texture residual, which is resampled according to the selected mode. Noise matched to the border's measured grain and a ramped blur are applied on top. Corners are filled in two passes so they inherit synthesized side texture. All randomness ramps in from zero at the seam, so the first synthesized line is an exact continuation of the edge.
Development
git clone https://github.com/ErikBavenstrand/cardbleed && cd cardbleed
uv run cardbleed --selfcheck # assertion suite (fixtures)
uv run cardbleed --selfcheck scan.png # plus checks against a real scan
uv run --group dev ruff check src
uv run --group dev pyright
Module layout: synthesis.py (edge analysis and border synthesis),
formats.py (format-preserving I/O, including the JPEG DCT path),
sizing.py (px/mm/target/aspect math), process.py (per-file pipeline),
cli.py, selfcheck.py.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cardbleed-0.2.0.tar.gz.
File metadata
- Download URL: cardbleed-0.2.0.tar.gz
- Upload date:
- Size: 3.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ee0e051838a31e22bb6c2e234d4f896463435b108e90c33996c3790cf7ede56
|
|
| MD5 |
b52b8c8406e68f812a7264e2286e8c8c
|
|
| BLAKE2b-256 |
7757ee8cdfe8b796503bb3ec3cd5d5124510ef3dfa34c1d431b2e2cbbd8f19f6
|
Provenance
The following attestation bundles were made for cardbleed-0.2.0.tar.gz:
Publisher:
release.yml on ErikBavenstrand/cardbleed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cardbleed-0.2.0.tar.gz -
Subject digest:
4ee0e051838a31e22bb6c2e234d4f896463435b108e90c33996c3790cf7ede56 - Sigstore transparency entry: 2070405564
- Sigstore integration time:
-
Permalink:
ErikBavenstrand/cardbleed@9778e8b67f146f5ece3bd30bbef6ceb6a5ca3c27 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ErikBavenstrand
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9778e8b67f146f5ece3bd30bbef6ceb6a5ca3c27 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cardbleed-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cardbleed-0.2.0-py3-none-any.whl
- Upload date:
- Size: 28.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28167dfe8defa5a86dba7ef8c79f8a2a88ce29853a83639ca26329e31a6549ca
|
|
| MD5 |
40e95dc54e6787387d283fd540ab8cdc
|
|
| BLAKE2b-256 |
29d8e4dc27cd0476896ebdf88b781254973152ed0075efeb36cb20cd6fcb3dd5
|
Provenance
The following attestation bundles were made for cardbleed-0.2.0-py3-none-any.whl:
Publisher:
release.yml on ErikBavenstrand/cardbleed
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cardbleed-0.2.0-py3-none-any.whl -
Subject digest:
28167dfe8defa5a86dba7ef8c79f8a2a88ce29853a83639ca26329e31a6549ca - Sigstore transparency entry: 2070405713
- Sigstore integration time:
-
Permalink:
ErikBavenstrand/cardbleed@9778e8b67f146f5ece3bd30bbef6ceb6a5ca3c27 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/ErikBavenstrand
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9778e8b67f146f5ece3bd30bbef6ceb6a5ca3c27 -
Trigger Event:
push
-
Statement type: