Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Font-Generator

example

Generate Font from png file:

Name png chracter files in their unicode name, such as "0.png" and "零.png"; put them in source directory, and convert it.

FontGenerator
├──fonts          font file output directory
├──images         input image store directory
├──potrace        svg generate software
├──readme-asset   assets
└──src            source code

Fast Run:

python ./src/main.py ./images/source-directory ./fonts/destination-font-name.ttf

Requirements

To run this program, please install these requirements:

opencv-python
pillow
numpy
fonttools
svgpath2mpl

and these software:

Potrace

unzip the package in /potrace/installer, and copy the executable file into /potrace/bin.

FontForge

I really recommand using this program under Linux enviroment. It is inconvinient to use fontforge as a python extention under Windows.

update:

change the method using fontforge to ffpython.

Install fontforge under Windows, add it's bin fold's path into var PATH, and enjoy it!

update 2:

Throw those old and poorly maintained software into the trash bin. Now we have a pure Python implementation (although still not perfect) as an alternative. Enjoy it!

Parameters

Functions: preprocess_image, preprocess_image_otsu

  • enhance(2.0): Enhances image contrast. 2.0 increases contrast; higher values yield more contrast.
  • medianBlur(img_np, 5): Reduces image noise. 5 is the kernel size; larger values increase smoothness.
  • adaptiveThreshold(..., 21, 5):
    • 21: Kernel size for local thresholding; larger values smooth the result.
    • 5: Constant subtracted from mean or weighted mean in thresholding.
  • threshold(..., cv2.THRESH_OTSU): Applies Otsu's method to find an optimal threshold value automatically.

Function: bitmap_to_svg

  • --opttolerance 0.2: Curve optimization tolerance in Potrace. Lower values retain more bitmap details.
  • --alphamax 3.5: Maximum angle for curve smoothing in Potrace. Higher values result in smoother curves.

License

Apache 2.0

About

generate fonts using .png file

Resources

Stars

11 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages