15 releases (2 stable)
1.0.2 | Aug 20, 2024 |
---|---|
1.0.0 | Apr 7, 2023 |
0.5.2 | Apr 6, 2023 |
0.4.0 | Apr 5, 2023 |
0.1.2 | Jan 2, 2023 |
#263 in Images
58 downloads per month
Used in spreadsheet-maker
140KB
374 lines
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.
Documentation
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");
}
Dependencies
~14MB
~249K SLoC