feat(config): Add option to never convert vector images

This commit is contained in:
Jesse Wierzbinski 2024-06-16 01:39:16 -10:00
parent 6ef3a854d9
commit de9dca5735
No known key found for this signature in database
3 changed files with 12 additions and 0 deletions

View file

@ -160,6 +160,8 @@ convert_images = true
# Can be: "image/jxl", "image/webp", "image/avif", "image/png", "image/jpeg", "image/heif", "image/gif" # Can be: "image/jxl", "image/webp", "image/avif", "image/png", "image/jpeg", "image/heif", "image/gif"
# JXL support will likely not work # JXL support will likely not work
convert_to = "image/webp" convert_to = "image/webp"
# Also convert SVG images?
convert_vector = false
# [s3] # [s3]
# Can be left blank if you don't use the S3 media backend # Can be left blank if you don't use the S3 media backend

View file

@ -224,10 +224,12 @@ export const configValidator = z.object({
.object({ .object({
convert_images: z.boolean().default(false), convert_images: z.boolean().default(false),
convert_to: z.string().default("image/webp"), convert_to: z.string().default("image/webp"),
convert_vector: z.boolean().default(false),
}) })
.default({ .default({
convert_images: false, convert_images: false,
convert_to: "image/webp", convert_to: "image/webp",
convert_vector: false,
}), }),
}) })
.default({ .default({

View file

@ -3,6 +3,7 @@
* @module MediaManager * @module MediaManager
* @description Handles media conversion between formats * @description Handles media conversion between formats
*/ */
import { config } from "config-manager";
import sharp from "sharp"; import sharp from "sharp";
export const supportedMediaFormats = [ export const supportedMediaFormats = [
@ -33,6 +34,13 @@ export class MediaConverter {
* @returns Whether the media is convertable * @returns Whether the media is convertable
*/ */
public isConvertable(file: File) { public isConvertable(file: File) {
if (
file.type === "image/svg+xml" &&
!config.media.conversion.convert_vector
) {
return false;
}
return supportedMediaFormats.includes(file.type); return supportedMediaFormats.includes(file.type);
} }