SDF-Generator
Command line tool to bulk generate signed distance fields from images.
The tool produces images with 1 channel of 16 bit (Gray16 in Golang).
References
Command line parameters
=== SDF Generator (github.com/maxfish/sdf-generator) ===
Usage of ./sdf-generate:
-channels string
Specify which channels of the input image can contribute to defining the "inner" area of the shape.
Accepted values are R,G,B,A and they can be specified separated with a comma.
E.g. 'R,A' means that the algorithm will consider a pixel "inside" the shape if the Red channel,
or the Alpha channel, are above the threshold. (default "A")
-crop
Specify if the resulting image should be cropped.
-downscale int
Sets the factor by which to downscale the image during processing. The output image will be smaller
than the input image by this factor, rounded downwards. Note: For greater accuracy, images to be used
as input for a distance field are often generated at higher resolution. (default 1)
-input string
Specify an input filename or a folder path.
-output string
Specify an output filename or a folder path. If input is a path then output must be a path.
-overwrite
Specify if the output file, when it already exists, can be overwritten.
WARNING: this flag is applied to the whole operation and it can delete many pre-existing images.
-spread float
Specify the spread of the distance field. The spread is the maximum distance in pixels that will be
scanned looking for a nearby edge. (default 4)
-threshold float
Specify the threshold applied to the channels for one pixel to be considered "inside" the source shape.
The accepted values go from 0.0 to 1.0. (default 0.5)
-alpha bool
Output the signed distance field to the alpha channel instead of using gray color values. (default false)
Example
Process a whole folder:
./sdf-generate -input example/input -output example/output
Process a single image:
./sdf-generate -input example/input/ic_backup_black_48dp\ 2.png -output example/output/test.png
Results
Input image |
Output image |
|
|
- The image is correctly centered in the resulting file
- Images with content touching the edges (the case above) are correctly handled
- The resulting image is bigger than the original one (with downscale=1) because space is made available for the spread
- Currently, only 1-channel images are produced (Gray16)
A couple of common wrong results generated by similar tools:
Image |
Problem |
|
Spread outside of the boundaries. It is cut on both the left and the right sides. |
|
Image not centered |