pub struct ThumbnailConfig {
pub max_width: u32,
pub max_height: u32,
pub format: ImageFormat,
}Expand description
Configuration builder for image thumbnail generation.
Encapsulates maximum bounding box constraints and the target output image encoding format.
§Examples
use image::ImageFormat;
use scyph_storage::thumbnail::ThumbnailConfig;
let config = ThumbnailConfig::new(300, 300)
.with_format(ImageFormat::Png);
assert_eq!(config.max_width, 300);
assert_eq!(config.max_height, 300);
assert_eq!(config.format, ImageFormat::Png);Fields§
§max_width: u32Maximum allowable width in pixels.
max_height: u32Maximum allowable height in pixels.
format: ImageFormatTarget image encoding format for the generated thumbnail (default: JPEG).
Implementations§
Source§impl ThumbnailConfig
impl ThumbnailConfig
Sourcepub const fn new(max_width: u32, max_height: u32) -> ThumbnailConfig
pub const fn new(max_width: u32, max_height: u32) -> ThumbnailConfig
Creates a new ThumbnailConfig with custom maximum width and height bounds.
By default, encodes output as JPEG.
§Arguments
max_width- Maximum thumbnail width in pixels.max_height- Maximum thumbnail height in pixels.
Sourcepub fn with_format(self, format: ImageFormat) -> ThumbnailConfig
pub fn with_format(self, format: ImageFormat) -> ThumbnailConfig
Configures the destination image encoding format (e.g. JPEG, PNG, WebP).
§Arguments
format- TargetImageFormat.
Sourcepub async fn generate(
&self,
data: impl Into<Bytes>,
) -> Result<Vec<u8>, StorageError>
pub async fn generate( &self, data: impl Into<Bytes>, ) -> Result<Vec<u8>, StorageError>
Generates a thumbnail buffer from the provided raw image bytes using this configuration.
Preserves original aspect ratio while scaling down to fit within (max_width, max_height).
§Arguments
data- Raw bytes of the source image (cheaply shared ifBytes).
§Errors
Returns StorageError::ValidationError if image format is unsupported or bytes are corrupt,
or StorageError::Internal if re-encoding fails.
Sourcepub const fn content_type(&self) -> &'static str
pub const fn content_type(&self) -> &'static str
Returns the canonical MIME content-type string for this configuration’s target output format.
§Examples
use image::ImageFormat;
use scyph_storage::thumbnail::ThumbnailConfig;
let config = ThumbnailConfig::default().with_format(ImageFormat::WebP);
assert_eq!(config.content_type(), "image/webp");Sourcepub const fn extension(&self) -> &'static str
pub const fn extension(&self) -> &'static str
Returns the canonical file extension (without leading dot) for this configuration’s format.
Sourcepub fn derive_key(&self, original_key: &str, subfolder: &str) -> String
pub fn derive_key(&self, original_key: &str, subfolder: &str) -> String
Derives the destination storage key for a thumbnail based on this configuration’s format.
Replaces the original extension with the target format extension and places the file in subfolder.
§Examples
use image::ImageFormat;
use scyph_storage::thumbnail::ThumbnailConfig;
let config = ThumbnailConfig::default().with_format(ImageFormat::WebP);
let key = config.derive_key("avatars/user.png", "thumbnails");
assert_eq!(key, "avatars/thumbnails/user.webp");Trait Implementations§
Source§impl Clone for ThumbnailConfig
impl Clone for ThumbnailConfig
Source§fn clone(&self) -> ThumbnailConfig
fn clone(&self) -> ThumbnailConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ThumbnailConfig
Source§impl Debug for ThumbnailConfig
impl Debug for ThumbnailConfig
Source§impl Default for ThumbnailConfig
impl Default for ThumbnailConfig
Source§fn default() -> ThumbnailConfig
fn default() -> ThumbnailConfig
impl Eq for ThumbnailConfig
Source§impl PartialEq for ThumbnailConfig
impl PartialEq for ThumbnailConfig
impl StructuralPartialEq for ThumbnailConfig
Auto Trait Implementations§
impl Freeze for ThumbnailConfig
impl RefUnwindSafe for ThumbnailConfig
impl Send for ThumbnailConfig
impl Sync for ThumbnailConfig
impl Unpin for ThumbnailConfig
impl UnsafeUnpin for ThumbnailConfig
impl UnwindSafe for ThumbnailConfig
Blanket Implementations§
impl<T> Authorizable for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request