Skip to main content

penmimic

Write any text in your own handwriting from Python. Fill in a printable template, photograph it, and penmimic cuts out your letters and uses them to write whatever you like, as a PNG or an animated GIF.

The problem

Typed text feels impersonal. Existing handwriting tools are closed, limited, or hard to use from code.

The solution

A small library with a short API:

from penmimic import Writer

w = Writer.from_samples("my_samples/")
w.write("Hello world").save("note.png")
w.write("Hello world").animate("note.gif")

Each letter is picked at random from five of your own versions, then given a tiny random change in size, tilt, height and spacing, so the page does not look copy-pasted.

Install

pip install penmimic

Python 3.10+. For the optional web demo: pip install "penmimic[demo]".

Use it

1. Print the template(s) (5 A4 pages each). There are two: block letters and cursive.

penmimic --make-templates templates/                 # makes both PDFs
penmimic --make-template block.pdf                   # just block
penmimic --make-template cursive.pdf --style cursive # just cursive

In the cursive sheet, every a-z box has a dotted baseline, an x-height line, a filled dot (start) and a hollow dot (end). Write one natural letter with a short lead-in at the filled dot and a short flick at the hollow dot. You do not have to fill in both sheets: fill the style(s) you want. Photos of both can sit in the same folder. 2. Fill it in with a dark pen. Write every character in every box, sitting on the dotted line.

3. Photograph each page. Whole page in view, flat, good light, plain surface, held upright (portrait). Put the photos in a folder, e.g. my_samples/. File names do not matter: each page is recognised from the small squares in its header.

4. Write.

from penmimic import Writer
w = Writer.from_samples("my_samples/", style="cursive")   # or "block" (default); letters saved in my_samples/glyphs_cursive/
w.write("Dear diary,\nToday was good.", size=1.2, ink="navy", paper="lined",
        line_spacing=1.8, jitter=0.8, seed=42).save("diary.png")

Command line:

penmimic "Hello world" --samples my_samples --style cursive -o note.png
penmimic "Hello world" --samples my_samples -o note.gif --paper lined --ink navy

Options for write()

Option Default Meaning
letter_spacing 1.0 0-3. Gap between letters (in cursive, above 1 opens the joins)
word_spacing 1.0 0-3. Gap between words
size 1.0 Text size (1.0 = as written on the template)
ink #1b1b3a Ink colour: name or hex
line_spacing 1.6 Gap between lines, as a multiple of a typical letter height
jitter 1.0 0 = identical letters, 1 = natural, 2 = messy (max)
paper plain plain or lined
width / margin 1600 / 80 Page size in pixels
seed None Same seed = same result every time

Demo website

pip install -e ".[demo]"
export PENMIMIC_SAMPLES=my_samples     # Windows PowerShell: $env:PENMIMIC_SAMPLES="my_samples"
python demo/app.py                     # open http://127.0.0.1:5000

Results

  • 44 automated tests pass (pytest). They use synthetic "handwriting" made from a computer font, photographed with simulated perspective, shadow and noise. They prove the pipeline works, not that it looks good on every real hand.
  • TODO: after trying it with your own handwriting, record here what you saw (e.g. which characters needed re-writing, how long extraction takes on your machine). Report only what you measured.

Limitations

  • Needs a clean template: a pen that is too light, boxes crossed by ink, or a dark/uneven background can break extraction.
  • Cursive mode overlaps and tightens letters inside a word so they touch, but it still pastes separate letter images; it does not draw one continuous pen stroke.
  • Only the characters on the template (A-Z, a-z, 0-9, .,!?'"-:;()). Others fall back to the other case, then ?, then a blank gap.
  • Photos must show the whole page, roughly upright. Very strong shadows or extreme angles fail with a clear error.
  • It copies your letters; it does not learn how you write. A neural stroke model is planned for version 0.2.
  • Left-to-right scripts only.

Credits

  • Built by Ezzah Najmal.
  • Code drafted with help from Claude (Anthropic), then reviewed and tested by the author.
  • Libraries: OpenCV, Pillow, NumPy, Flask, pytest.

Licence

MIT. See LICENSE. Handwriting samples are personal data: only use your own or ones you have permission to use.

Metadata

Release files for PenMimic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PenMimic 0.1.0
File Size Uploaded Provenance Actions
penmimic-0.1.0.tar.gz 28.8 kB Without provenance Details for penmimic-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PenMimic 0.1.0
File Interpreter ABI Platform Actions
penmimic-0.1.0-py3-none-any.whl Python 3 none any Details for penmimic-0.1.0-py3-none-any.whl

Total release size: 49.8 kB

Release files / penmimic-0.1.0.tar.gz

Download URL penmimic-0.1.0.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
61e0b910f7c5d9c169f40651da0fa9fcd11dfbfa8bc739a8588e768d28fd7b5f
BLAKE2b-256 checksum
How to use checksums
f726e6055db97160b2faf2751ea199fd80da72411049e4e5eadc0876d070c82d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / penmimic-0.1.0-py3-none-any.whl

Download URL penmimic-0.1.0-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7321272480ff0901b05ccbb834b2d8c2fced697d5a5473d435f9b505ea757af
BLAKE2b-256 checksum
How to use checksums
67fcd19d7f187de600ead43c3b63bdc90ce22110b6525e7701c72ccc077f5d3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for PenMimic 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page