diff --git a/Iceshrimp.Backend/Core/Configuration/Config.cs b/Iceshrimp.Backend/Core/Configuration/Config.cs index 569e6cdd..e7cf4ce2 100644 --- a/Iceshrimp.Backend/Core/Configuration/Config.cs +++ b/Iceshrimp.Backend/Core/Configuration/Config.cs @@ -203,9 +203,10 @@ public sealed class Config public ImagePipelineSection ImagePipeline { get; init; } = new(); public readonly int MaxFileSizeBytes = 10 * 1024 * 1024; - public Enums.ImageProcessor ImageProcessor { get; init; } = Enums.ImageProcessor.ImageSharp; - public int MaxResolutionMpx { get; init; } = 30; - public bool LocalOnly { get; init; } = false; + public Enums.ImageProcessor ImageProcessor { get; init; } = Enums.ImageProcessor.ImageSharp; + public int MaxResolutionMpx { get; init; } = 30; + public bool LocalOnly { get; init; } = false; + public bool FailIfImageExceedsMaxRes { get; init; } = false; [Range(0, 128)] public int ImageProcessorConcurrency { get; init; } = 8; diff --git a/Iceshrimp.Backend/Core/Services/DriveService.cs b/Iceshrimp.Backend/Core/Services/DriveService.cs index 312d5f50..a9f10ddb 100644 --- a/Iceshrimp.Backend/Core/Services/DriveService.cs +++ b/Iceshrimp.Backend/Core/Services/DriveService.cs @@ -263,9 +263,16 @@ public class DriveService( } else if (ident.Width * ident.Height > storageConfig.Value.MediaProcessing.MaxResolutionPx) { + var config = storageConfig.Value.MediaProcessing; + if (config.FailIfImageExceedsMaxRes) + { + // @formatter:off + throw GracefulException.UnprocessableEntity($"Image is larger than {config.MaxResolutionMpx}mpx. Please resize your image to fit within the allowed dimensions."); + // @formatter:on + } + logger.LogDebug("Image is larger than {mpx}mpx ({width}x{height}), bypassing image processing...", - storageConfig.Value.MediaProcessing.MaxResolutionMpx, ident.Width, - ident.Height); + config.MaxResolutionMpx, ident.Width, ident.Height); skipImageProcessing = true; } diff --git a/Iceshrimp.Backend/configuration.ini b/Iceshrimp.Backend/configuration.ini index ebec0628..b9f0bd0e 100644 --- a/Iceshrimp.Backend/configuration.ini +++ b/Iceshrimp.Backend/configuration.ini @@ -158,9 +158,14 @@ MaxFileSize = 10M ;; Maximum resolution for files to be considered for image processing, in megapixels ;; Note that processing an image requires up to 4MB of system memory per megapixel, in some edge case scenarios. -;; Caution: metadata (e.g. location data) for locally originating images will *not* be stripped for files larger than this +;; Caution: metadata (e.g. location data) for locally originating images will *not* be stripped for files larger than this. +;; If this is unwanted behavior, enable FailIfImageExceedsMaxRes. MaxResolutionMpx = 30 +;; Should you prefer to reject locally originating images that exceed MaxResolutionMpx, set this option to true. +;; Note that this does not apply to remote images, or to local images in a format not supported by the configured image processor. +FailIfImageExceedsMaxRes = false + ;; Maxmimum concurrent image encode tasks to run. (0 = no limit) ImageProcessorConcurrency = 8