@@ -430,11 +430,12 @@ impl<'a> BlobObject<'a> {
430430
431431 if do_scale {
432432 let n_px_longest_side = max ( img. width ( ) , img. height ( ) ) ;
433+ let n_all_px = img. width ( ) * img. height ( ) ;
433434
434435 // target_wh will be used as the target-resolution for resizing the image,
435436 // so that the longest sides of the image match the target-resolution.
436437 let mut target_wh = if !is_avatar {
437- let n_all_px_sqrt = f64:: from ( img . width ( ) * img . height ( ) ) . sqrt ( ) ;
438+ let n_all_px_sqrt = f64:: from ( n_all_px ) . sqrt ( ) ;
438439 // Limit resolution to the number of pixels that fit within max_wh * max_wh,
439440 // so that the image-quality does not depend on the aspect-ratio.
440441 let mut resolution_limit =
@@ -458,15 +459,13 @@ impl<'a> BlobObject<'a> {
458459 self :: add_white_bg ( & mut img) ;
459460 }
460461
461- // resize() results in often slightly better quality,
462- // however, comes at high price of being 4+ times slower than thumbnail().
463- // for a typical camera image that is sent, this may be a change from "instant" (500ms) to "long time waiting" (3s).
464- // as we do not have recoding in background while chat has already a preview,
465- // we vote for speed.
466- // exception is the avatar image: this is far more often sent than recoded,
467- // usually has less pixels by cropping, UI that needs to wait anyways,
468- // and also benefits from slightly better (5%) encoding of Triangle-filtered images.
469- let new_img = if is_avatar {
462+ // resize() results in better quality than thumbnail(),
463+ // however, comes at the price of being 4+ times slower than thumbnail().
464+ // For a typical camera-image that is sent (often more than 8 megapixels),
465+ // this may be a change from "instant" (500ms) to "long time waiting" (3s).
466+ // As we do not have recoding in the background while the chat already has a preview,
467+ // we vote for speed, if the original image has a high resolution (> 2.56 megapixels).
468+ let new_img = if is_avatar || n_all_px <= 1600 * 1600 {
470469 img. resize ( target_wh, target_wh, image:: imageops:: FilterType :: Triangle )
471470 } else {
472471 img. thumbnail ( target_wh, target_wh)
0 commit comments