Skip to content

theatrus/stamp-maker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stamp-maker

Turn a positive rubber-stamp image into a laser-ready depth map with support ramps, for depth engraving on xTool (and similar) laser engravers.

Input positive Output depth map
Positive stamp artwork Generated depth map with ramps

Why

To laser-engrave a rubber stamp you need the artwork inverted (the ink areas stay at full height while everything else is cut away) and mirrored (so the stamp prints the right way around). That part is easy.

The hard part is that thin features — letter strokes, fine lines, dots — become tall, skinny posts of soft rubber. Without support they flex under stamping pressure, print badly, and eventually tear off. Commercially made stamps solve this with shoulders: sloped ramps that widen each feature toward its base. xTool Creative Space's depth engraving mode will happily follow a grayscale depth map, but it has no notion of ramps and can't generate them itself.

stamp-maker closes that gap. It takes your artwork as you'd see it printed (dark ink on a light background) and produces a grayscale depth map where every raised feature is skirted by a properly sloped shoulder:

  1. Threshold the input into a crisp ink mask (anti-aliased edges are fine). Images with an alpha channel are composited over white first, so transparent backgrounds just work.
  2. Mirror horizontally.
  3. Distance transform: an exact Euclidean distance transform (Felzenszwalb–Huttenlocher) computes each pixel's distance to the nearest feature, so shoulders follow every outline at a constant width — including the inside of counters and between close features.
  4. Ramp mapping: distance is mapped through a selectable profile into an 8-bit grayscale depth value. Beyond the ramp width the depth is capped at a flat, full-depth floor.

In the output, white = full stamp height (untouched rubber) and black = full engrave depth, matching xTool's depth-mode convention.

Install

With Rust installed (rustup.rs):

cargo install --path .

or run straight from a checkout with cargo run --release --.

Usage

stamp-maker input.png -o depth.png [OPTIONS]

Typical invocation for a 300 DPI positive engraved 1.5 mm deep:

stamp-maker stamp.png -o stamp-depth.png --dpi 300 --depth 1.5 --angle 35 --profile concave

Options

Option Default Meaning
--dpi <DPI> 300 Resolution of the input image. Match the resolution you'll use in xTool Creative Space, or the physical ramp width will be off.
--depth <MM> 1.5 How deep the laser will cut the open areas. Only used to size the ramps — the actual cut depth is set in your laser software.
--angle <DEG> 35 Shoulder angle, measured from vertical. 0 = straight walls (no ramp). Larger angles give wider, more supportive shoulders.
--profile <P> linear Ramp cross-section shape — see below.
--threshold <0-255> 128 Pixels darker than this count as ink (with --from-alpha: pixels at least this opaque).
--from-alpha Mask on the alpha channel instead of luminance (opaque = ink). Use for artwork of any color drawn on a transparent background.
--no-flip Skip the horizontal mirror (e.g. if your artwork is already mirrored).
--white-deep Invert output polarity so white = deepest cut, if your engraver expects the opposite mapping.

The horizontal ramp width is depth × tan(angle) and is printed after each run so you can sanity-check it — e.g. 1.5 mm deep at 35° gives a 1.05 mm shoulder.

Ramp profiles

Profile Cross-section
linear Straight slope from face edge to full depth. Simple and predictable.
concave Steep at the face, flaring out at the base — the classic commercial stamp shoulder. Keeps the printed edge crisp while giving the widest base support.
convex Gentle at the face, steepening toward the base.
scurve Smooth ease-in/ease-out between face and floor.

The concave profile at 45°:

Concave profile depth map

Tips

  • Verify polarity on scrap first. This tool assumes xTool depth mode cuts black deepest. If your first test engraves the face away instead of the background, re-run with --white-deep.
  • Keep DPI consistent between this tool and your laser software. The ramps are sized in pixels from --dpi; importing the PNG at a different resolution scales the shoulders too.
  • Laser rubber engraves with lots of debris — use air assist and clean the stamp (soapy water and a soft brush) before mounting.
  • Very small text may need a wider shoulder (--angle 45 or more) or a slightly shallower --depth to survive.

Development

cargo test

Unit tests cover the distance transform, ramp geometry, mirroring, polarity, alpha handling, and profile math.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages