From 75d79dc79ca254923bfb910a136a26be81bf826a Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 1 Nov 2020 23:47:46 +0100 Subject: [PATCH] use different avatar-sizes for different media_quality settings --- src/blob.rs | 11 ++++++++++- src/config.rs | 10 +++++----- src/constants.rs | 3 ++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/blob.rs b/src/blob.rs index ba46a1e96..d9943eec1 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -380,7 +380,16 @@ impl<'a> BlobObject<'a> { pub async fn recode_to_avatar_size(&self, context: &Context) -> Result<(), BlobError> { let blob_abs = self.to_abs_path(); - self.recode_to_size(context, blob_abs, AVATAR_SIZE).await + let img_wh = if MediaQuality::from_i32(context.get_config_int(Config::MediaQuality).await) + .unwrap_or_default() + == MediaQuality::Balanced + { + BALANCED_AVATAR_SIZE + } else { + WORSE_AVATAR_SIZE + }; + + self.recode_to_size(context, blob_abs, img_wh).await } pub async fn recode_to_image_size(&self, context: &Context) -> Result<(), BlobError> { diff --git a/src/config.rs b/src/config.rs index 7ea8909a2..3f8c768c6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -287,7 +287,7 @@ mod tests { use std::string::ToString; use crate::constants; - use crate::constants::AVATAR_SIZE; + use crate::constants::BALANCED_AVATAR_SIZE; use crate::test_utils::*; use image::GenericImageView; use num_traits::FromPrimitive; @@ -336,8 +336,8 @@ mod tests { assert_eq!(img.height(), 1000); let img = image::open(avatar_blob).unwrap(); - assert_eq!(img.width(), AVATAR_SIZE); - assert_eq!(img.height(), AVATAR_SIZE); + assert_eq!(img.width(), BALANCED_AVATAR_SIZE); + assert_eq!(img.height(), BALANCED_AVATAR_SIZE); } #[async_std::test] @@ -362,8 +362,8 @@ mod tests { assert_eq!(avatar_cfg, avatar_src.to_str().map(|s| s.to_string())); let img = image::open(avatar_src).unwrap(); - assert_eq!(img.width(), AVATAR_SIZE); - assert_eq!(img.height(), AVATAR_SIZE); + assert_eq!(img.width(), BALANCED_AVATAR_SIZE); + assert_eq!(img.height(), BALANCED_AVATAR_SIZE); } #[async_std::test] diff --git a/src/constants.rs b/src/constants.rs index 9edf40f8e..8d6eb243d 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -196,7 +196,8 @@ pub const DC_LP_AUTH_FLAGS: i32 = DC_LP_AUTH_OAUTH2 | DC_LP_AUTH_NORMAL; pub const DC_FETCH_EXISTING_MSGS_COUNT: i64 = 100; // max. width/height of an avatar -pub const AVATAR_SIZE: u32 = 192; +pub const BALANCED_AVATAR_SIZE: u32 = 256; +pub const WORSE_AVATAR_SIZE: u32 = 128; // max. width/height of images pub const BALANCED_IMAGE_SIZE: u32 = 1280;