Skip to content

Commit

Permalink
use different avatar-sizes for different media_quality settings
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s authored and link2xt committed Nov 29, 2020
1 parent 2720d34 commit 75d79dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/blob.rs
Expand Up @@ -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> {
Expand Down
10 changes: 5 additions & 5 deletions src/config.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion src/constants.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 75d79dc

Please sign in to comment.