mirror of
https://github.com/chatmail/core.git
synced 2026-05-14 12:26:31 +03:00
use different avatar-sizes for different media_quality settings
This commit is contained in:
11
src/blob.rs
11
src/blob.rs
@@ -380,7 +380,16 @@ impl<'a> BlobObject<'a> {
|
|||||||
pub async fn recode_to_avatar_size(&self, context: &Context) -> Result<(), BlobError> {
|
pub async fn recode_to_avatar_size(&self, context: &Context) -> Result<(), BlobError> {
|
||||||
let blob_abs = self.to_abs_path();
|
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> {
|
pub async fn recode_to_image_size(&self, context: &Context) -> Result<(), BlobError> {
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ mod tests {
|
|||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
|
|
||||||
use crate::constants;
|
use crate::constants;
|
||||||
use crate::constants::AVATAR_SIZE;
|
use crate::constants::BALANCED_AVATAR_SIZE;
|
||||||
use crate::test_utils::*;
|
use crate::test_utils::*;
|
||||||
use image::GenericImageView;
|
use image::GenericImageView;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
@@ -336,8 +336,8 @@ mod tests {
|
|||||||
assert_eq!(img.height(), 1000);
|
assert_eq!(img.height(), 1000);
|
||||||
|
|
||||||
let img = image::open(avatar_blob).unwrap();
|
let img = image::open(avatar_blob).unwrap();
|
||||||
assert_eq!(img.width(), AVATAR_SIZE);
|
assert_eq!(img.width(), BALANCED_AVATAR_SIZE);
|
||||||
assert_eq!(img.height(), AVATAR_SIZE);
|
assert_eq!(img.height(), BALANCED_AVATAR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
@@ -362,8 +362,8 @@ mod tests {
|
|||||||
assert_eq!(avatar_cfg, avatar_src.to_str().map(|s| s.to_string()));
|
assert_eq!(avatar_cfg, avatar_src.to_str().map(|s| s.to_string()));
|
||||||
|
|
||||||
let img = image::open(avatar_src).unwrap();
|
let img = image::open(avatar_src).unwrap();
|
||||||
assert_eq!(img.width(), AVATAR_SIZE);
|
assert_eq!(img.width(), BALANCED_AVATAR_SIZE);
|
||||||
assert_eq!(img.height(), AVATAR_SIZE);
|
assert_eq!(img.height(), BALANCED_AVATAR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
|
|||||||
@@ -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;
|
pub const DC_FETCH_EXISTING_MSGS_COUNT: i64 = 100;
|
||||||
|
|
||||||
// max. width/height of an avatar
|
// 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
|
// max. width/height of images
|
||||||
pub const BALANCED_IMAGE_SIZE: u32 = 1280;
|
pub const BALANCED_IMAGE_SIZE: u32 = 1280;
|
||||||
|
|||||||
Reference in New Issue
Block a user