From 3fb34048a1efc0a24766288d3d2d0b7f30c141c4 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 6 Aug 2023 15:30:58 +0200 Subject: transcode width grid --- server/src/routes/ui/assets.rs | 4 +++- transcoder/src/image.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index 2d175f9..f2c3f3f 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -47,7 +47,9 @@ pub async fn r_item_assets( let asset = asset.unwrap_or(AssetLocation::Assets( PathBuf::from_str("fallback.jpeg").unwrap(), )); - let path = jellytranscoder::image::transcode(asset, 50., 5, width.unwrap_or(2048))?; + // fit the resolution into a finite set so the maximum cache is finite too. + let width = 2usize.pow(width.unwrap_or(2048).clamp(128, 8196).ilog2()); + let path = jellytranscoder::image::transcode(asset, 50., 5, width)?; info!("loading asset from {path:?}"); Ok(( ContentType::AVIF, diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs index d721e7b..29ad423 100644 --- a/transcoder/src/image.rs +++ b/transcoder/src/image.rs @@ -39,7 +39,7 @@ pub fn transcode( image.width() as usize, image.height() as usize, ))?; - info!("writing to cache: {path:?}"); + info!("transcode finished"); File::create(&path)?.write_all(&encoded.avif_file)?; } Ok(path) -- cgit v1.2.3-70-g09d2