diff --git a/.changeset/common-signs-punch.md b/.changeset/common-signs-punch.md new file mode 100644 index 000000000000..199a795992d7 --- /dev/null +++ b/.changeset/common-signs-punch.md @@ -0,0 +1,5 @@ +--- +'astro': major +--- + +Adds support for converting SVGs to raster images (PNGs, WebP, etc) to the default Sharp image service - ([v6 upgrade guidance](https://v6.docs.astro.build/en/guides/upgrade-to/v6/#changed-svg-rasterization)) diff --git a/packages/astro/src/assets/services/service.ts b/packages/astro/src/assets/services/service.ts index 65570cb2d959..f138d123d1c8 100644 --- a/packages/astro/src/assets/services/service.ts +++ b/packages/astro/src/assets/services/service.ts @@ -198,10 +198,7 @@ export function verifyOptions(options: ImageTransform): void { throw new AstroError(AstroErrorData.IncompatibleDescriptorOptions); } - if ( - (options.src.format === 'svg' && options.format !== 'svg') || - (options.src.format !== 'svg' && options.format === 'svg') - ) { + if (options.src.format !== 'svg' && options.format === 'svg') { throw new AstroError(AstroErrorData.UnsupportedImageConversion); } } @@ -229,17 +226,16 @@ export function verifyOptions(options: ImageTransform): void { export const baseService: Omit = { propertiesToHash: DEFAULT_HASH_PROPS, validateOptions(options) { - // We currently do not support processing SVGs, so whenever the input format is a SVG, force the output to also be one - if (isESMImportedImage(options.src) && options.src.format === 'svg') { - options.format = 'svg'; - } - // Run verification-only checks verifyOptions(options); // Apply defaults and normalization separate from verification if (!options.format) { - options.format = DEFAULT_OUTPUT_FORMAT; + if (isESMImportedImage(options.src) && options.src.format === 'svg') { + options.format = 'svg'; + } else { + options.format = DEFAULT_OUTPUT_FORMAT; + } } if (options.width) options.width = Math.round(options.width); if (options.height) options.height = Math.round(options.height);