diff --git a/src/content/docs/en/guides/images.mdx b/src/content/docs/en/guides/images.mdx index 2588b39f0a9d8..9cb5972fd4039 100644 --- a/src/content/docs/en/guides/images.mdx +++ b/src/content/docs/en/guides/images.mdx @@ -700,3 +700,24 @@ If you were using the image integration in Astro v2.x, complete the following st You can now declare an associated image for a content collections entry, such as a blog post's cover image, in your frontmatter using its path relative to the current folder. The new `image` helper for content collections lets you validate the image metadata using Zod. Learn more about [how to use images in content collections](/en/guides/images/#images-in-content-collections) + +### Navigating Image Imports in Astro v3.0 + +In Astro v3.0, if you have to preserve the old import behavior for images and require a string representation of the image's URL, append `?url` to the end of your image path when importing it. For example: + +```astro title="src/pages/blog/MyImages.astro" +--- +import Sprite from '../assets/logo.svg?url'; +--- + + + + + +``` + +This approach ensures you obtain the URL string. Keep in mind that during development, Astro uses a `src/` path, but upon building, it generates hashed paths like `/_astro/cat.a6737dd3.png`. + +If you prefer to work directly with the image object itself, you can access the `.src` property. This approach is best for tasks like managing image dimensions for Core Web Vitals metrics and preventing CLS. + +If you are transitioning into the new import behavior, combining `?url` and `.src` methods might be the right method for seamless image handling.