Struct rckive_genpdf::elements::Image
source · pub struct Image { /* private fields */ }
Expand description
An image to embed in the PDF.
Only available if the images
feature is enabled.
This struct is a wrapper around the configurations printpdf::Image
exposes.
Supported Formats
All formats supported by the image
should be supported by this crate. The BMP, JPEG and
PNG formats are well tested and known to work. Yet it is currently not possible to render
images with transparency, see printpdf
issue #98.
Note that only the GIF, JPEG, PNG, PNM, TIFF and BMP formats are enabled by default. If you
want to use other formats, you have to add the image
crate as a dependency and activate the
required feature.
Example
use std::convert::TryFrom;
use rckive_genpdf::elements;
let image = elements::Image::from_path("examples/images/test_image.jpg")
.expect("Failed to load test image")
.with_alignment(rckive_genpdf::Alignment::Center) // Center the image on the page.
.with_scale(rckive_genpdf::Scale::new(0.5, 2)); // Squeeze and then stretch upwards.
Implementations§
source§impl Image
impl Image
sourcepub fn from_dynamic_image(data: DynamicImage) -> Result<Self, Error>
pub fn from_dynamic_image(data: DynamicImage) -> Result<Self, Error>
Creates a new image from an already loaded image.
sourcepub fn from_reader<R>(reader: R) -> Result<Self, Error>where
R: BufRead + Read + Seek,
pub fn from_reader<R>(reader: R) -> Result<Self, Error>where
R: BufRead + Read + Seek,
Creates a new image from the given reader.
sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn from_path(path: impl AsRef<Path>) -> Result<Self, Error>
Creates a new image by reading from the given path.
sourcepub fn set_position(&mut self, position: impl Into<Position>)
pub fn set_position(&mut self, position: impl Into<Position>)
Translates the image over to position.
sourcepub fn with_position(self, position: impl Into<Position>) -> Self
pub fn with_position(self, position: impl Into<Position>) -> Self
Translates the image over to position and returns it.
sourcepub fn with_scale(self, scale: impl Into<Scale>) -> Self
pub fn with_scale(self, scale: impl Into<Scale>) -> Self
Scales the image and returns it.
sourcepub fn set_alignment(&mut self, alignment: impl Into<Alignment>)
pub fn set_alignment(&mut self, alignment: impl Into<Alignment>)
Sets the alignment to use for this image.
sourcepub fn with_alignment(self, alignment: impl Into<Alignment>) -> Self
pub fn with_alignment(self, alignment: impl Into<Alignment>) -> Self
Sets the alignment to use for this image and returns it.
sourcepub fn set_clockwise_rotation(&mut self, rotation: impl Into<Rotation>)
pub fn set_clockwise_rotation(&mut self, rotation: impl Into<Rotation>)
Sets the clockwise rotation of the image around the bottom left corner.
sourcepub fn with_clockwise_rotation(self, rotation: impl Into<Rotation>) -> Self
pub fn with_clockwise_rotation(self, rotation: impl Into<Rotation>) -> Self
Sets the clockwise rotation of the image around the bottom left corner and then returns the image.