Skip to content

Cannot request svg output format for svg source files #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sgarner opened this issue Apr 8, 2025 · 0 comments · May be fixed by #262
Open

Cannot request svg output format for svg source files #261

sgarner opened this issue Apr 8, 2025 · 0 comments · May be fixed by #262
Labels

Comments

@sgarner
Copy link

sgarner commented Apr 8, 2025

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:

ipx/src/ipx.ts

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,
};
}
}

Logs

@sgarner sgarner added the bug label Apr 8, 2025
@sgarner sgarner linked a pull request Apr 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant