Struct image_builder::Image
source · pub struct Image<'a> { /* private fields */ }Expand description
This is the structure of the image that will be created. Use the new function to get started.
It is important to remember that the order in which elements are added to the image defines which
element goes on top of which. For example, adding text that starts at point 0,0 and then adding a
rectangle that also starts at the same point will cause the rectangle to cover the text. However,
by reversing the order and adding the rectangle first, it will be placed underneath the text. It
is essential to keep this order in mind when creating images with multiple elements to ensure that
the elements are in the desired order.
Examples
let mut image = Image::new(500, 500, colors::WHITE);
image.add_text(Text::new("Image Builder"));
image.add_rect(Rect::new().size(200, 200)); // This rectangle covers the text.let mut image = Image::new(500, 500, colors::WHITE);
image.add_rect(Rect::new().size(200, 200)); // This rectangle is in the background of the text.
image.add_text(Text::new("Image Builder"));Implementations§
source§impl<'a> Image<'a>
impl<'a> Image<'a>
sourcepub fn new(width: u32, height: u32, background: Color) -> Image<'a>
pub fn new(width: u32, height: u32, background: Color) -> Image<'a>
This method creates a new instance of an image, setting the background color, and size in pixels, and allocating memory to add fonts and elements to be drawn.
Example
use image_builder::{colors, Image};
let mut image = Image::new(400, 300, colors::GRAY);sourcepub fn add_custom_font(&mut self, name: &'a str, font: Vec<u8>)
pub fn add_custom_font(&mut self, name: &'a str, font: Vec<u8>)
The add_custom_font method requires that a .ttf font file (not provided) be loaded using fs.read,
and internally linked to the provided name in a HashMap. This will allow you to use this font in
your text by simply passing the font name as a parameter. Trying to use a font that has not been
previously loaded can cause the application to panic. Additionally, providing an invalid Vec
Example
use image_builder::Image;
use std::fs;
let mut image = //Image::new...
let roboto_bold = fs::read("fonts/Roboto/Roboto-Bold.ttf").unwrap();
image.add_custom_font("Roboto bold", roboto_bold);sourcepub fn add_picture(&mut self, picture: Picture)
pub fn add_picture(&mut self, picture: Picture)
With this method, it is possible to add an image on top of the image being built, taking into account
transparent backgrounds. This means that transparent areas of the added image will not overlap areas
already drawn in the main image. Please refer to the Picture for more details.
sourcepub fn add_text(&mut self, text: Text)
pub fn add_text(&mut self, text: Text)
This method allows for adding formatted text to the image being built. Refer to the Text for more details.
pub fn add_rect(&mut self, rect: Rect)
pub fn save(&mut self, file_name: &str)
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Image<'a>
impl<'a> Send for Image<'a>
impl<'a> Sync for Image<'a>
impl<'a> Unpin for Image<'a>
impl<'a> UnwindSafe for Image<'a>
Blanket Implementations§
§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere Scheme: ApproxScheme,
§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,
§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, DefaultApprox>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where Self: Sized + ApproxInto<Dst, DefaultApprox>,
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.