mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user