Blyx Nest Blyx language
Registry / Library
library · v0.1.0

AspectFit

Fit an image inside a box while preserving aspect ratio.

Source repository · Package JSON

Use AspectFit

use vendor::aspectfit::aspectfit;

Run the example

nest demo aspectfit@0.1.0
blyxc native-run aspectfit-demo/main.blyx
Example source and expected output
use vendor::aspectfit::aspectfit;

fn main() {
    let width = 400.0;
    let height = 200.0;
    let box_w = 100.0;
    let box_h = 100.0;
    let upscale = 0.0;
    let result = aspectfit_contain(width, height, box_w, box_h, upscale);
    if len(result) == 0 { println!("invalid"); return; }
    let mut i = 0;
    while i < len(result) {
        println!(at(result, i));
        i += 1;
    }
}

Expected output

100
50
0.25

Published versions

VersionPackageSource commitSHA-256
0.1.0Download ZIP2ec8d55a8e3f5de4567f403c556b81ddacde9432ae41fd4c97894dc01d38c5e6313c4c2cab