Closed aaronleopold closed 1 year ago
I can take it
Hey @berkingurcan thanks! Sorry for the late reply, been extra busy lately. Here you'll find all of the image thumbnail generation logic.
Essentially, what I was thinking was to update what's there, and add a few new functions for the new formats, to allow future custom scaling options. Something like:
/// The size factor to use when generating a thumbnail. This can be a
/// scaled factor, where the height and width are scaled by the same factor, a
/// a custom factor, where the height and width are scaled by different factors,
/// or a specific size, where the height and width are set to the specified size.
///
/// All floats are clamped to the range [0.0, 1.0].
pub enum ThumbnailSizeFactor {
Scaled(f32),
CustomScaled((f32, f32)),
Sized((u32, u32)),
}
/// The format to use when generating a thumbnail.
pub enum ThumbnailFormat {
Webp,
Jpeg,
JpegXl,
Png,
}
pub struct ThumbnailConfig {
pub size_factor: ThumbnailSizeFactor,
pub format: ThumbnailFormat,
}
impl Default for ThumbnailConfig {
fn default() -> Self {
Self {
size_factor: ThumbnailSizeFactor::Scaled(0.5),
format: ThumbnailFormat::Webp,
}
}
}
So the thumbnail functions would take a reference to a ThumbnailConfig
that controls some of the hard coded values throughout that file. It might be worth while to consider splitting my image.rs
into a crate with multiple modules per format, and have some sort of factory pattern for uniformity. E.g:
image/jpg.rs
from_path
from_bytes
image/png.rs
from_path
from_bytes
But, I'll leave that up to you. I think for now you can leave the jpeg-xl format alone, since it would require pulling in https://github.com/inflation/jpegxl-rs, but if you want to try it feel free.
Resolved from https://github.com/aaronleopold/stump/pull/134
I'd like to add additional configuration options around thumbnail generation. Primarily, I'd like to support the following:
I will need to decide whether this should be library or server level options.
General tasks:
image
crate that handles the conversion