Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnail quality options #44

Closed
3 of 8 tasks
aaronleopold opened this issue Sep 16, 2022 · 3 comments
Closed
3 of 8 tasks

Thumbnail quality options #44

aaronleopold opened this issue Sep 16, 2022 · 3 comments
Labels
core Relating to Stump's Rust core

Comments

@aaronleopold
Copy link
Collaborator

aaronleopold commented Sep 16, 2022

I'd like to add additional configuration options around thumbnail generation. Primarily, I'd like to support the following:

  • JPG, JPEG-XL, WEBP export format (currently only WEBP)
  • Customizable scale factor (0-1, default currently is 0.75)
  • Customizable dimensions (maybe, might be too much of a hassle)

I will need to decide whether this should be library or server level options.

General tasks:

  • Create generalized wrapper function in my image crate that handles the conversion
    • should accept the options selected from user
  • Update WEBP conversion to accept options
  • Create functions to convert buffer to:
    • JPG
    • JPEG-XL
    • WEBP
    • PNG
@aaronleopold aaronleopold added this to the 0.1.0 milestone Sep 16, 2022
@berkingurcan
Copy link
Contributor

I can take it

@aaronleopold
Copy link
Collaborator Author

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
  • etc

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
Copy link
Collaborator Author

Resolved from #134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Relating to Stump's Rust core
Projects
None yet
Development

No branches or pull requests

2 participants