pub struct ImageAssetOptions { /* private fields */ }
Expand description
Options for an image asset
Implementations§
Source§impl ImageAssetOptions
impl ImageAssetOptions
Sourcepub const fn with_preload(self, preload: bool) -> Self
pub const fn with_preload(self, preload: bool) -> Self
Make the asset preloaded
Preloading an image will make the image start to load as soon as possible. This is useful for images that will be displayed soon after the page loads or images that may not be visible immediately, but should start loading sooner
const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_preload(true));
Sourcepub const fn with_format(self, format: ImageFormat) -> Self
pub const fn with_format(self, format: ImageFormat) -> Self
Sets the format of the image
Choosing the right format can make your site load much faster. Webp and avif images tend to be a good default for most images
const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_format(ImageFormat::Webp));
Sourcepub const fn with_avif(self) -> Self
pub const fn with_avif(self) -> Self
Sets the format of the image to ImageFormat::Avif
Avif images tend to be a good default for most images rendered in browser because they compress images well
const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_avif());
Sourcepub const fn with_webp(self) -> Self
pub const fn with_webp(self) -> Self
Sets the format of the image to ImageFormat::Webp
Webp images tend to be a good default for most images rendered in browser because they compress images well
const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_webp());
Sourcepub const fn with_jpg(self) -> Self
pub const fn with_jpg(self) -> Self
Sets the format of the image to ImageFormat::Jpg
Jpeg images compress much better than ImageFormat::Png
, but worse than ImageFormat::Webp
or ImageFormat::Avif
const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_jpg());
Sourcepub const fn with_png(self) -> Self
pub const fn with_png(self) -> Self
Sets the format of the image to ImageFormat::Png
Png images don’t compress very well, so they are not recommended for large images
const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_png());
Sourcepub const fn format(&self) -> ImageFormat
pub const fn format(&self) -> ImageFormat
Get the format of the image
Sourcepub const fn with_size(self, size: ImageSize) -> Self
pub const fn with_size(self, size: ImageSize) -> Self
Sets the size of the image
If you only use the image in one place, you can set the size of the image to the size it will be displayed at. This will make the image load faster
const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_size(ImageSize::Manual { width: 512, height: 512 }));
Sourcepub const fn into_asset_options(self) -> AssetOptions
pub const fn into_asset_options(self) -> AssetOptions
Convert the options into options for a generic asset
Trait Implementations§
Source§impl Clone for ImageAssetOptions
impl Clone for ImageAssetOptions
Source§fn clone(&self) -> ImageAssetOptions
fn clone(&self) -> ImageAssetOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more