Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/common-signs-punch.md
Original file line number Diff line number Diff line change
@@ -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))
16 changes: 6 additions & 10 deletions packages/astro/src/assets/services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -229,17 +226,16 @@ export function verifyOptions(options: ImageTransform): void {
export const baseService: Omit<LocalImageService, 'transform'> = {
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);
Expand Down