use different avatar-sizes for different media_quality settings

This commit is contained in:
B. Petersen
2020-11-01 23:47:46 +01:00
committed by link2xt
parent 2720d34594
commit 75d79dc79c
3 changed files with 17 additions and 7 deletions

View File

@@ -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> {

View File

@@ -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]

View File

@@ -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;