fix: AVIF compress fails because Sharp metadata reports heif not avif

Sharp's metadata() returns format:"heif" for AVIF files. The compress
function was using this raw value without normalizing through FORMAT_MAP,
so toFormat("heif",...) was called which requires a compression option.
Now both explicit and detected formats go through FORMAT_MAP, mapping
heif→avif correctly.
This commit is contained in:
ashim-hq
2026-04-21 10:27:02 +08:00
parent dc9160746e
commit 966d7abaf0
@@ -21,9 +21,10 @@ export async function compress(image: Sharp, options: CompressOptions): Promise<
const { quality, targetSizeBytes, format } = options;
const metadata = await image.metadata();
const outputFormat = format
? (FORMAT_MAP[format] as keyof import("sharp").FormatEnum)
: ((metadata.format as keyof import("sharp").FormatEnum) ?? "jpeg");
const detected = metadata.format ?? "jpeg";
const outputFormat = (
FORMAT_MAP[format ?? ""] ?? FORMAT_MAP[detected] ?? detected
) as keyof import("sharp").FormatEnum;
if (targetSizeBytes !== undefined) {
if (targetSizeBytes <= 0) {