#puzzle #svg #template #game #graphics

jigsaw_puzzle_generator

Library for generating jigsaw puzzle images

4 releases

0.2.0 Nov 30, 2024
0.1.2 Oct 31, 2024
0.1.1 Oct 29, 2024
0.1.0 Oct 29, 2024

#328 in Images

Download history 281/week @ 2024-10-25 87/week @ 2024-11-01 9/week @ 2024-11-08 2/week @ 2024-11-15 124/week @ 2024-11-29 25/week @ 2024-12-06

151 downloads per month

MIT/Apache

48KB
1K SLoC

crates.io MIT/Apache 2.0 Documentation

Jigsaw Puzzle Generator

jigsaw_puzzle_generator is a simple helper to generate jigsaw puzzle in Rust. Inspired by the puzzle-paths

Usage

use env_logger::{Builder, Env};
use jigsaw_puzzle_generator::JigsawGenerator;
use std::env;
use std::fs::create_dir_all;

fn main() {
    if env::var("RUST_LOG").is_err() {
        env::set_var("RUST_LOG", "debug")
    }
    let env = Env::default();
    Builder::from_env(env).format_timestamp_millis().init();
    let image_path = env::args().nth(1).unwrap_or("raw.jpg".to_string());
    let template = JigsawGenerator::from_path(&image_path, 9, 6)
        .expect("Failed to load image")
        .generate(false)
        .expect("Failed to generate puzzle");
    create_dir_all("images").expect("Failed to create images directory");
    template
        .origin_image
        .save("images/origin_image.png")
        .expect("Failed to save image");

    for piece in template.pieces.iter() {
        piece
            .crop(&template.origin_image)
            .save(format!("images/puzzle_piece_{}.png", piece.index))
            .expect("Failed to save image");
    }
}

Dependencies

~14MB
~331K SLoC