-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: svg rasterization upgrade guide #13039
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
base: v6
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for astro-docs-2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
delucis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great — thanks for taking care of it @Princesseuh!
Left one small nit, but otherwise LGTM.
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
sarah11918
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Princesseuh ! As a breaking change, this should go in one of the categories below with a full entry below linking to the PR, following the format of the others.
Left some suggestions below as to what that could look like!
| ### SVG rasterization | ||
|
|
||
| Astro's default Sharp image service now supports converting SVG files to raster files (such as PNG, WebP, etc.). Note that this is subject to many limitations, for instance SVGs with embedded fonts might not be converted properly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ### SVG rasterization | |
| Astro's default Sharp image service now supports converting SVG files to raster files (such as PNG, WebP, etc.). Note that this is subject to many limitations, for instance SVGs with embedded fonts might not be converted properly. | |
| ### Changed: SVG rasterization | |
| In Astro v5.x, Astro's default Sharp image service was unable to convert SVG files to raster files (e.g. PNG, WebP). This meant that the `<Image />` component would ignore any value set for `format` when optimizing and transforming SVG files. | |
| Astro 6.0 now supports SVG rasterization. This is subject to many limitations, for instance SVGs with embedded fonts might not be converted properly. However, when the `format` property is set, the image service will now attempt to convert SVG images. |
Something like this would fit our pattern. Please edit if incorrect or not the most helpful way to describe this!
|
|
||
| #### What should I do? | ||
|
|
||
| If you were previously relying on code like this to automatically skip SVGs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| If you were previously relying on code like this to automatically skip SVGs: | |
| If you were previously relying the fact that the image service would automatically skip converting SVGs, you must now check for the format of your images beforehand to avoid converting SVGs to raster images: |
| ```astro | ||
| <Image src={imageThatMightBeAnSvg} format="avif" alt="example" /> | ||
| ``` | ||
|
|
||
| You'll now need to check the format beforehand to avoid converting SVGs to raster images: | ||
|
|
||
| ```astro {3} | ||
| <Image | ||
| src={imageThatMightBeAnSvg} | ||
| format={imageThatMightBeAnSvg.src.format === "svg" ? "svg" : "avif"} | ||
| alt="example" | ||
| /> | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```astro | |
| <Image src={imageThatMightBeAnSvg} format="avif" alt="example" /> | |
| ``` | |
| You'll now need to check the format beforehand to avoid converting SVGs to raster images: | |
| ```astro {3} | |
| <Image | |
| src={imageThatMightBeAnSvg} | |
| format={imageThatMightBeAnSvg.src.format === "svg" ? "svg" : "avif"} | |
| alt="example" | |
| /> | |
| ``` | |
| ```astro del={1} ins=(3-7} | |
| <Image src={imageThatMightBeAnSvg} format="avif" alt="example" /> | |
| <Image | |
| src={imageThatMightBeAnSvg} | |
| format={imageThatMightBeAnSvg.src.format === "svg" ? "svg" : "avif"} | |
| alt="example" | |
| /> | |
| ``` | |
| <ReadMore>Learn more about [the `format` image property](/en/reference/modules/astro-assets/#format)</ReadMore> |
Description (required)
withastro/astro#15180 coming in v6!