Crate distance_field

source ·
Expand description

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 similar to this:

use std::fs::File;
use 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(distance_field::Options {
        size: (128, 128),
        max_distance: 256,

    // Save it to 'output' as a PNG

fn main() {
    convert_image_to_dfield("img/input.png", "output.png");


  • The options passed as the argument to the distance_field method.