Skip to content

Commit a32210d

Browse files
committed
feat: Use the available file-size for avatar-images better
The resolution-limits for avatar-images are currently 512x512 or 128x128. Reducing the resolution further, to 2/3 each step, can reduce the quality much more than is necessary to fit within the file-size-limits, which are currently 60 kB or 20 kB. An image made entirely of noise (which results in unusually large file-sizes), encoded with jpeg-quality 75, and 4:2:2-colour-subsampling (the format currently used for encoding images), can be below 60 kB at 227x227. For the lower file-size-limit of 20 kB, such images with a resolution of 128x128 already fit. More normal images will have a lower file-size at the same resolution. Before this change, the target-resolutions for resizing were: 512x512 -> 341x341 -> 227x227. And for the lower file-size-limit: 128x128 (does already fit). After this change, the target-resolutions for resizing will be: 512x512 -> 448x448 -> 392x392 -> 343x343 -> 300x300 -> 263x263 -> 230x230. And for the lower file-size-limit, those will be: 256x256 -> 224x224 -> 196x196 -> 172x172 -> 150x150 -> 131x131. The resolution-limit has been increased to 256x256, because the file-size of many images is still smaller than 20 kB when encoded at 256x256, and it can be a large improvement in quality.
1 parent f12afdf commit a32210d

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/blob.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ impl<'a> BlobObject<'a> {
483483
));
484484
}
485485

486-
target_wh = target_wh * 2 / 3;
486+
// Note: This is only done for avatar-images.
487+
target_wh = target_wh * 7 / 8;
487488
} else {
488489
info!(
489490
context,

src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub const WORSE_IMAGE_BYTES: usize = 130_000;
199199
// max. width/height and bytes of an avatar
200200
pub(crate) const BALANCED_AVATAR_SIZE: u32 = 512;
201201
pub(crate) const BALANCED_AVATAR_BYTES: usize = 60_000;
202-
pub(crate) const WORSE_AVATAR_SIZE: u32 = 128;
202+
pub(crate) const WORSE_AVATAR_SIZE: u32 = 256;
203203
pub(crate) const WORSE_AVATAR_BYTES: usize = 20_000; // this also fits to Outlook servers don't allowing headers larger than 32k.
204204

205205
// max. width/height of images scaled down because of being too huge

0 commit comments

Comments
 (0)