-
Notifications
You must be signed in to change notification settings - Fork 74
Open
Labels
Description
Environment
ipx v3.0.3
Reproduction
n/a
Describe the bug
Requesting an SVG source file without specifying an output format is allowed — it returns the SVG file unmodified (or optimised, if SVGO is enabled).
But requesting an SVG source file and explicitly specifying svg
as the output format produces a JPEG output file.
This is because other file types cannot be converted to SVG, so svg
is not listed in SUPPORTED_FORMATS
and unsupported formats are transformed to jpeg
.
The logic ought to be amended so that SVG -> SVG is acceptable.
Additional context
The relevant logic is here:
Lines 224 to 252 in af698d0
const format = | |
mFormat && SUPPORTED_FORMATS.has(mFormat) | |
? mFormat | |
: SUPPORTED_FORMATS.has(imageMeta.type || "") // eslint-disable-line unicorn/no-nested-ternary | |
? imageMeta.type | |
: "jpeg"; | |
// Use original SVG if format is not specified | |
if (imageMeta.type === "svg" && !mFormat) { | |
if (options.svgo === false) { | |
return { | |
data: sourceData, | |
format: "svg+xml", | |
meta: imageMeta, | |
}; | |
} else { | |
// https://github.com/svg/svgo | |
const { optimize } = await getSVGO(); | |
const svg = optimize(sourceData.toString("utf8"), { | |
...options.svgo, | |
plugins: ["removeScriptElement", ...(options.svgo?.plugins || [])], | |
}).data; | |
return { | |
data: svg, | |
format: "svg+xml", | |
meta: imageMeta, | |
}; | |
} | |
} |