From 4f836950bc7efd95370ea8612a7a820b4cb07998 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sun, 1 Nov 2020 22:31:55 +0100 Subject: [PATCH] split off image recoding to separate function --- src/blob.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/blob.rs b/src/blob.rs index f6da962f5..62780a567 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -408,12 +408,6 @@ impl<'a> BlobObject<'a> { return Ok(()); } - let img = image::open(&blob_abs).map_err(|err| BlobError::RecodeFailure { - blobdir: context.get_blobdir().to_path_buf(), - blobname: blob_abs.to_str().unwrap_or_default().to_string(), - cause: err, - })?; - let img_wh = if MediaQuality::from_i32(context.get_config_int(Config::MediaQuality).await) .unwrap_or_default() == MediaQuality::Balanced @@ -423,6 +417,21 @@ impl<'a> BlobObject<'a> { WORSE_IMAGE_SIZE }; + self.recode_to_size(context, blob_abs, img_wh).await + } + + async fn recode_to_size( + &self, + context: &Context, + blob_abs: PathBuf, + img_wh: u32, + ) -> Result<(), BlobError> { + let img = image::open(&blob_abs).map_err(|err| BlobError::RecodeFailure { + blobdir: context.get_blobdir().to_path_buf(), + blobname: blob_abs.to_str().unwrap_or_default().to_string(), + cause: err, + })?; + if img.width() <= img_wh && img.height() <= img_wh { return Ok(()); }