ImageToFontConverter is a small WPF tool (C# / .NET 9) that converts a folder of PNG glyph images into a TrueType font (TTF). It vectorizes PNG alpha masks into SVGs using Emgu.CV (OpenCV) and automates FontForge with a generated Python script to produce the final font. The app includes a simple GUI with progress reporting and cancellation.
- PNG → SVG vectorization using Emgu.CV
- Automated FontForge script generation and execution
- Produces a
.ttffont and keeps intermediate SVGs for inspection - Simple WPF GUI with progress and cancellation support
- .NET 9 SDK
- Visual Studio 2026 (recommended) with the .NET desktop development workload
- FontForge installed and available on PATH or in one of the common install locations
- Emgu.CV NuGet packages referenced by the solution and the native OpenCV/Emgu runtime (platform native dependencies)
- (Windows) Visual C++ Redistributable may be required by native Emgu/OpenCV binaries
- Clone the repository:
git clone https://github.com/SirDiabo/ImageToFontConverter.git
- Open the solution in Visual Studio: File > Open > Project/Solution and select the
.sln. - Restore NuGet packages (Project > Restore NuGet Packages if needed).
- Confirm target framework is
.NET 9in Right-click Project > Properties > Target Framework. - Build the solution: Build > Build Solution.
- Run the app: Debug > Start Debugging (F5) or Debug > Start Without Debugging (Ctrl+F5).
- Input must be PNG files with an alpha channel (RGBA). The converter uses the alpha channel to detect glyph contours.
- Place all glyph PNGs in a single folder (top-level). The app does not recurse subfolders.
- Filenames define the mapping to Unicode codepoints. Conventions supported by
FontConverter:upper_A.png,upper_B.png, ... →A..Zlower_a.png,lower_b.png, ... →a..z0.png..9.png→ digits- Punctuation:
space,exclamation,questionmark,period,comma,colon,semicolon,hyphen,endash,emdash,ellipsis,degree,bullet,middot - Brackets & Quotes:
leftparenthesis,rightparenthesis,leftbracket,rightbracket,leftbrace,rightbrace,angleleft,angleright,singlequote,doublequote,backtick - Math:
plus,equal,caret,percent,asterisk,divide,multiply,plusminus,lessthan,greaterthan - Symbols:
at,hash,ampersand,underscore,tilde,backslash,forwardslash,verticalbar,copyright,trademark,registered - Currency:
dollar,euro,pound,yen,cent - Accented lowercase:
lower_e_acute(é),lower_e_grave(è),lower_e_circ(ê),lower_e_uml(ë),lower_a_acute(á),lower_a_grave(à),lower_a_circ(â),lower_a_uml(ä),lower_a_ring(å),lower_o_acute(ó),lower_o_circ(ô),lower_o_uml(ö),lower_u_acute(ú),lower_u_grave(ù),lower_u_uml(ü),lower_i_acute(í),lower_i_circ(î),lower_n_tilde(ñ),lower_c_cedil(ç),lower_ss(ß),lower_ae(æ) - Accented uppercase:
upper_A_uml(Ä),upper_O_uml(Ö),upper_U_uml(Ü),upper_A_grave(À),upper_A_ring(Å),upper_E_acute(É),upper_N_tilde(Ñ),upper_C_cedil(Ç),upper_AE(Æ)
space.pngis treated specially — it creates an empty glyph with a default advance width; the image content is ignored.- Accented characters use compound filenames like
lower_e_acute.pngfor é,lower_ss.pngfor ß,upper_AE.pngfor Æ, and so on. The table above lists all supported names with their corresponding characters.
Tip: use clean, high-contrast alpha masks (opaque glyph area, transparent background) for best tracing results.
- Launch the app and use the Browse button to select the input folder.
- The UI reports how many expected glyph files were found (based on
FontConverter.ExpectedGlyphs). - Adjust the Simplification slider to reduce or increase contour detail (higher = fewer points).
- Enter a Font Name. The output filename will be
<FontName>.ttfand will be the font's internal install name. - Click Convert. Progress is shown in the UI. Conversion can be cancelled.
- On success you will find:
<FontName>.ttfin the input folderconverted/subfolder with generated.svgfiles
MainWindow.xaml.csdrives the UI: folder selection, progress updates, and cancellation.FontConverter.csdoes the heavy lifting:- Finds FontForge executable (
FindFontForgeExecutable()checks common paths andwhere). - Loads PNGs with Emgu.CV and extracts the alpha channel.
- Thresholds the alpha channel and finds contours (
CvInvoke.FindContours). - Approximates contours and writes SVG path data (preserving holes via contour hierarchy).
- Generates a FontForge Python script that maps filenames to Unicode values, imports SVGs, sets metrics, and writes a TTF.
- Launches FontForge with redirected stdout/stderr and parses
PROGRESS:lines for UI updates.
- Finds FontForge executable (
- Temporary Python script is created and deleted automatically (if you need it for debugging, check the code and add logging before deletion).
<FontName>.ttf— final TrueType font (written to the input folder)converted/*.svg— intermediate SVGs (kept for inspection)- Progress messages and errors are shown in the app UI; the app surfaces FontForge output to help debugging.
- "FontForge not detected" — install FontForge and make sure it is on PATH or in a common location scanned by the app.
- "No PNG files found" — ensure
.pngfiles exist at the top level of the selected folder. - "No contours found" — check the PNG alpha channel; if the glyph is drawn on an opaque background, contour detection will fail.
- Complex glyphs can produce very complex SVGs; increase simplification to reduce path complexity.
- If FontForge fails, inspect the app output and the (temporary) generated Python script for the cause.
MainWindow.xaml/MainWindow.xaml.cs— WPF UI and interaction logicFontConverter.cs— PNG → SVG logic, FontForge script creation and process orchestrationGlyphsWindow(if present) — UI helper to inspect found glyphsREADME.md— this file