Progressive image component using Svelte (granted that you already have the images).
Run yarn add -D svelte-progressive-image
.
Then use it in your svelte files like that:
<script>
import Image from "svelte-progressive-image";
let name = 'image-name';
</script>
<Image {name}>
The result looks like:
<picture>
<source
srcset="[email protected] 254w,
[email protected] 338w,
[email protected] 389w,
[email protected] 518w,
[email protected] 676w,
[email protected] 777w,
[email protected] 892w,
[email protected] 960w,
[email protected] 1036w,
[email protected] 1280w,
[email protected] 1338w,
[email protected] 1382w,
[email protected] 1784w,
[email protected] 1920w,
[email protected] 2560w"
sizes="(max-width: 992px) 892px,
(max-width: 768px) 691px,
(max-width: 576px) 518px,
(max-width: 375px) 338px,
1280px"
type="image/webp"
>
<img
srcset="[email protected] 254w,
[email protected] 338w,
[email protected] 389w,
[email protected] 518w,
[email protected] 676w,
[email protected] 777w,
[email protected] 892w,
[email protected] 960w,
[email protected] 1036w,
[email protected] 1280w,
[email protected] 1338w,
[email protected] 1382w,
[email protected] 1784w,
[email protected] 1920w,
[email protected] 2560w"
sizes="(max-width: 992px) 892px,
(max-width: 768px) 691px,
(max-width: 576px) 518px,
(max-width: 375px) 338px,
1280px"
src="[email protected]"
alt="Alternative text"
class="w-90-percent max-width-1280"
>
</picture>
Check the Image.svelte
for the exported variables, their types and defaults.
These include:
name
of the imagewidths
that are used to create the srcSet attribute.defaultWidth
of the img to be shown if nothing else works.sizes
that makes the max-width media query for the screen-image.largestImageSize
which is the image size for the max window size.alt
attribute for alternative text for the image.imageClass
for any class that we need to style our component.