In your current Astro project, just replace the import of the native Astro
<Image>
or
<Picture>
component with the ones provided by
astro-lqip
or import the
<Background>
component for CSS background images.
Image
- import { Image } from 'astro:components';+ import { Image } from 'astro-lqip/components';
Picture
- import { Picture } from 'astro:components';+ import { Picture } from 'astro-lqip/components';
Background
+ import { Background } from 'astro-lqip/components';
Since version
1.6.0
, you can also put the image path as string directly in the
src
prop. Support absolute paths in
src
folder, relative paths and alias.
Both
<Image>
and
<Picture>
components support all the props of the
native Astro components
but adds a couple of props for LQIP management:
lqip
: The LQIP type to use. It can be one of the following:
base64
: Generates a Base64-encoded LQIP image. (default option)
color
: Generates a solid color placeholder. Not compatible with
lqipSize
.
css
: Generates a CSS-based LQIP image.
svg
: Generates an SVG-based LQIP image.
lqipSize
: The size of the LQIP image, which can be any number from
4
to
64
. (default is 4)
Warning
A high value for
lqipSize
can significantly increase the total size of your website.
Example:
---import { Image, Picture } from 'astro-lqip/components';import image from '/src/assets/images/image.png';import otherImage from '/src/assets/images/other-image.png';---<Image src={image} alt="Cover Image" width={220} height={220} lqip="svg" lqipSize={10} /><Picture src={otherImage} alt="Other cover Image" width={220} height={220} lqip="css" lqipSize={7} />
Tip
For the
<Image>
component, a
parentAttributes
prop similar to
pictureAttributes
has been added.
Background
The
<Background>
component supports the following props:
src
(required): The source of the background image located in
src
folder. It can be a static import, absolute path, relative path, alias path or remote URL.
lqip
: The LQIP type to use. It can be one of the following:
base64
: Generates a Base64-encoded LQIP image. (default option)
color
: Generates a solid color placeholder.
cssVariable
: A string that represents the name of the CSS variable to store the background data.
By default, the background data is stored in a CSS variable named
--background
.
For responsive backgrounds, the CSS variable names are generated based on the provided widths, following the pattern
--background-small
(lower than 768px),
--background-medium
(768px to 1199px),
--background-large
(1200px to 1919px) and
--background-xlarge
(1920px and above).
--background
is also generated for the largest image for backward compatibility.
If the
cssVariable
prop is provided, the generated CSS variable names will follow the pattern
--{cssVariable}-small
,
--{cssVariable}-medium
,
--{cssVariable}-large
and
--{cssVariable}-xlarge
.
format
: The image format to use for the background. It can be one of the following in string or an array of strings. If an array is provided, this generates multiple background images with the native
image-set()
CSS function, which allows the browser to choose the best format to use based on its support:
avif
webp
(default option)
jpeg
png
widths
: An array of numbers that represents the widths to use for responsive background images.
width
: The width to use for the background image. This prop is ignored if the
widths
prop is provided.
height
: The height to use for the background image. This prop is ignored if the
widths
prop is provided.
quality
: The quality to use for the background image. It can be a number from
1
to
100
.
fit
: The fit to use for the background image. It can be one of the following: