2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 11:21:24 +00:00

Add control over gif frame count

This commit is contained in:
asonix 2023-02-04 17:52:23 -06:00
parent 88ca9793e8
commit 4cc810d372
6 changed files with 17 additions and 3 deletions

View file

@ -39,6 +39,7 @@ cache_duration = 168
max_width = 128
max_height = 128
max_area = 16384
max_frame_count = 100
[repo]
type = "sled"

View file

@ -224,6 +224,14 @@ max_height = 128
# depending on whether video uploads are enabled
max_area = 16384
# Optional: Maximum number of frames permitted in uploaded gifs
# environment variable: PICTRS__MEDIA__GIF__MAX_FRAME_COUNT
# default: 100
#
# If a gif does not fit within this bound, it will either be transcoded to a video or rejected,
# depending on whether video uploads are enabled
max_frame_count = 100
## Database configuration
[repo]

View file

@ -462,19 +462,19 @@ struct Run {
media_max_frame_count: Option<usize>,
/// Maximum width allowed for gif uploads.
///
/// If an upload exceeds this value, it will be transcoded to a video format or aborted,
/// If an upload exceeds this value, it will be transcoded to a video format or rejected,
/// depending on whether video uploads are enabled.
#[arg(long)]
media_gif_max_width: Option<usize>,
/// Maximum height allowed for gif uploads
///
/// If an upload exceeds this value, it will be transcoded to a video format or aborted,
/// If an upload exceeds this value, it will be transcoded to a video format or rejected,
/// depending on whether video uploads are enabled.
#[arg(long)]
media_gif_max_height: Option<usize>,
/// Maximum area allowed for gif uploads
///
/// If an upload exceeds this value, it will be transcoded to a video format or aborted,
/// If an upload exceeds this value, it will be transcoded to a video format or rejected,
/// depending on whether video uploads are enabled.
#[arg(long)]
media_gif_max_area: Option<usize>,

View file

@ -81,6 +81,7 @@ struct GifDefaults {
max_height: usize,
max_width: usize,
max_area: usize,
max_frame_count: usize,
}
#[derive(Clone, Debug, serde::Serialize)]
@ -187,6 +188,7 @@ impl Default for GifDefaults {
max_height: 128,
max_width: 128,
max_area: 16384,
max_frame_count: 100,
}
}
}

View file

@ -128,6 +128,8 @@ pub(crate) struct Gif {
pub(crate) max_height: usize,
pub(crate) max_area: usize,
pub(crate) max_frame_count: usize,
}
impl Media {

View file

@ -33,6 +33,7 @@ impl TranscodeOptions {
if details.width <= media.gif.max_width
&& details.height <= media.gif.max_height
&& details.width * details.height <= media.gif.max_area
&& details.frames.unwrap_or(1) <= media.gif.max_frame_count
{
return Self {
input_format,