stumpapp / stump

A free and open source comics, manga and digital book server with OPDS support (WIP)
https://stumpapp.dev
MIT License
970 stars 44 forks source link

Thumbnail quality options #44

Closed aaronleopold closed 1 year ago

aaronleopold commented 2 years ago

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:

berkingurcan commented 1 year ago

I can take it

aaronleopold commented 1 year ago

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:

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.

aaronleopold commented 1 year ago

Resolved from https://github.com/aaronleopold/stump/pull/134