Skip to content

Commit 8780ff2

Browse files
Princesseuhjcayzacdelucissarah11918
authored
add support for SVG rasterization (#15180)
* add support for SVG rasterization * revert change to noop service * removed forgotten check * revert code I mistakenly removed * fixes default format for SVG * Update .changeset/common-signs-punch.md Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> * chore: changeset * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> --------- Co-authored-by: Julien Cayzac <julien.cayzac@rakuten.com> Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
1 parent 50c9129 commit 8780ff2

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

.changeset/common-signs-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': major
3+
---
4+
5+
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))

packages/astro/src/assets/services/service.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ export function verifyOptions(options: ImageTransform): void {
198198
throw new AstroError(AstroErrorData.IncompatibleDescriptorOptions);
199199
}
200200

201-
if (
202-
(options.src.format === 'svg' && options.format !== 'svg') ||
203-
(options.src.format !== 'svg' && options.format === 'svg')
204-
) {
201+
if (options.src.format !== 'svg' && options.format === 'svg') {
205202
throw new AstroError(AstroErrorData.UnsupportedImageConversion);
206203
}
207204
}
@@ -229,17 +226,16 @@ export function verifyOptions(options: ImageTransform): void {
229226
export const baseService: Omit<LocalImageService, 'transform'> = {
230227
propertiesToHash: DEFAULT_HASH_PROPS,
231228
validateOptions(options) {
232-
// We currently do not support processing SVGs, so whenever the input format is a SVG, force the output to also be one
233-
if (isESMImportedImage(options.src) && options.src.format === 'svg') {
234-
options.format = 'svg';
235-
}
236-
237229
// Run verification-only checks
238230
verifyOptions(options);
239231

240232
// Apply defaults and normalization separate from verification
241233
if (!options.format) {
242-
options.format = DEFAULT_OUTPUT_FORMAT;
234+
if (isESMImportedImage(options.src) && options.src.format === 'svg') {
235+
options.format = 'svg';
236+
} else {
237+
options.format = DEFAULT_OUTPUT_FORMAT;
238+
}
243239
}
244240
if (options.width) options.width = Math.round(options.width);
245241
if (options.height) options.height = Math.round(options.height);

0 commit comments

Comments
 (0)