@@ -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 =
@@ -460,15 +461,13 @@ impl<'a> BlobObject<'a> {
460461 self :: add_white_bg ( & mut img) ;
461462 }
462463
463- // resize() results in often slightly better quality,
464- // however, comes at high price of being 4+ times slower than thumbnail().
465- // for a typical camera image that is sent, this may be a change from "instant" (500ms) to "long time waiting" (3s).
466- // as we do not have recoding in background while chat has already a preview,
467- // we vote for speed.
468- // exception is the avatar image: this is far more often sent than recoded,
469- // usually has less pixels by cropping, UI that needs to wait anyways,
470- // and also benefits from slightly better (5%) encoding of Triangle-filtered images.
471- let new_img = if is_avatar {
464+ // resize() results in better quality than thumbnail(),
465+ // however, comes at the price of being 4+ times slower than thumbnail().
466+ // For a typical camera-image that is sent (often more than 8 megapixels),
467+ // this may be a change from "instant" (500ms) to "long time waiting" (3s).
468+ // As we do not have recoding in the background while the chat already has a preview,
469+ // we vote for speed, if the original image has a high resolution (> 2.56 megapixels).
470+ let new_img = if is_avatar || n_all_px <= 1600 * 1600 {
472471 img. resize ( target_wh, target_wh, image:: imageops:: FilterType :: Triangle )
473472 } else {
474473 img. thumbnail ( target_wh, target_wh)
0 commit comments