Skip to content

Commit

Permalink
Resize post thumbnails (fixes #4053) (#5107)
Browse files Browse the repository at this point in the history
* Resize post thumbnails (fixes #4053)

* 256px
  • Loading branch information
Nutomic authored Oct 8, 2024
1 parent f5066b1 commit a051772
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/defaults.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
"ProxyAllImages"
# Timeout for uploading images to pictrs (in seconds)
upload_timeout: 30
# Resize post thumbnails to this maximum width/height.
max_thumbnail_size: 256
}
# Email sending configuration. All options except login/password are mandatory
email: {
Expand Down
5 changes: 3 additions & 2 deletions crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> L
// fetch remote non-pictrs images for persistent thumbnail link
// TODO: should limit size once supported by pictrs
let fetch_url = format!(
"{}image/download?url={}",
"{}image/download?url={}&resize={}",
pictrs_config.url,
encode(image_url.as_str())
encode(image_url.as_str()),
context.settings().pictrs_config()?.max_thumbnail_size
);

let res = context
Expand Down
4 changes: 4 additions & 0 deletions crates/utils/src/settings/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ pub struct PictrsConfig {
/// Timeout for uploading images to pictrs (in seconds)
#[default(30)]
pub upload_timeout: u64,

/// Resize post thumbnails to this maximum width/height.
#[default(256)]
pub max_thumbnail_size: u32,
}

#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document, PartialEq)]
Expand Down

0 comments on commit a051772

Please sign in to comment.