| Crates.io | om-fork-distance-field |
| lib.rs | om-fork-distance-field |
| version | 0.3.0-alpha |
| created_at | 2022-08-26 16:42:49.062416+00 |
| updated_at | 2025-11-25 07:42:44.753966+00 |
| description | Temporary fork! Generate distance fields from images for pseudo-vector rendering |
| homepage | https://github.com/AndreasOM/om-fork-distance-field |
| repository | https://github.com/AndreasOM/om-fork-distance-field.git |
| max_upload_size | |
| id | 652891 |
| size | 87,030 |
This is a temporary fork until a new upstream version is released against image>=0.25.9
A Rust library/executable for generating distance field bitmaps to render as pseudo-vector images in a shader
A Rust library/executable for generating distance field bitmaps to render as pseudo-vector images in a shader
Generate distance field bitmaps for rendering as pseudo-vector images in shaders.
An example usecase for the library would be to automatically convert asset images. You can achieve this by having a build.rs similar to this:
use std::fs::File;
use om_fork_distance_field::DistanceFieldExt;
fn convert_image_to_dfield(input: &str, output: &str) {
// Load the 'input' image
let img = image::open(input).unwrap();
// Generate a distance field from the image
let outbuf = img.grayscale().distance_field(om_fork_distance_field::Options {
size: (128, 128),
max_distance: 256,
..Default::default()
});
// Save it to 'output' as a PNG
image::DynamicImage::ImageLuma8(outbuf).save(output).unwrap();
}
fn main() {
convert_image_to_dfield("img/input.png", "output.png");
}
Checkout the repository and cd into it; then run:
cargo run --example generator -- img/input.png output.png 64 64
This will take the following image as input:

And generate a 64x64 distance field:

Now we can use the generated distance field to create a vector image.
First we need to scale it up with a linear interpolation:

Then we apply a treshold function:

You can see that we have something which looks very similar to the original input image and that just from a 64x64 image! But it's still very pixelated and doesn't look like a vector image. This can be fixed by not doing a hard treshold but allowing some shades of gray.