Skip to content

high-level library to generate simple PNG images.

Notifications You must be signed in to change notification settings

gertech/image-builder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Builder is a high-level library that uses the image crate as the engine to generate simple PNG images, but with convenience and simplicity.


Example

The code below generates the image at the top of this README.md file.

use std::fs;

use image_builder::{colors, FilterType, Image, Picture, Rect, Text};

fn main() {
    let width = 600;
    let height = 280;
    let mut image = Image::new(width, height, colors::GRAY);

    let roboto_bold = fs::read("fonts/Roboto/Roboto-Bold.ttf").unwrap();

    image.add_custom_font("Roboto bold", roboto_bold);

    image.add_rect(
        Rect::new()
            .size(width - 10, height - 10)
            .position(5, 5)
            .color(colors::PURPLE),
    );

    image.add_rect(
        Rect::new()
            .size(width - 30, height - 30)
            .position(15, 15)
            .color(colors::GRAY),
    );

    image.add_picture(
        Picture::new("logo.png")
            .resize(134, 83, FilterType::Triangle)
            .crop(41, 143, 536, 332)
            .position(233, 30),
    );

    image.add_text(
        Text::new("Image Builder")
            .size(90)
            .font("Roboto bold")
            .position(60, 125)
            .color([0, 0, 0, 100]),
    );

    image.add_text(
        Text::new("Image Builder")
            .size(90)
            .font("Roboto bold")
            .position(55, 120)
            .color(colors::PURPLE),
    );

    image.add_text(
        Text::new("This image was built using this library.")
            .size(30)
            .position(80, 220)
            .color(colors::ORANGE),
    );

    image.save("example.png");
}

About

high-level library to generate simple PNG images.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%