You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-15Lines changed: 21 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,13 @@ A Svelte component which uses CDNs to serve responsive images.
5
5
## Usage
6
6
7
7
### Install
8
+
8
9
`npm i @joeinnes/svelte-image`
9
10
10
11
### Import
12
+
11
13
Note that except for the 'alt' tag, all tags are optional and their default values are shown in the example below.
14
+
12
15
```
13
16
<script>
14
17
import { Image } from '@joeinnes/svelte-image';
@@ -28,16 +31,18 @@ provider.set({
28
31
```
29
32
30
33
Currently supported:
31
-
* Statically (zero configuration)
32
-
* Cloudimage (use your token as the 'key')
34
+
35
+
- Statically (zero configuration)
36
+
- Cloudimage (use your token as the 'key')
33
37
34
38
```
35
39
provider.set({
36
40
name: 'cloudimage',
37
41
key: 'cloudimage_token'
38
42
})
39
43
```
40
-
* Cloudinary (you need to create an HTTP Proxy media source, and then use your cloud name as the key)
44
+
45
+
- Cloudinary (you need to create an HTTP Proxy media source, and then use your cloud name as the key)
41
46
42
47
```
43
48
provider.set({
@@ -48,13 +53,14 @@ provider.set({
48
53
49
54
## Notes and Caveats
50
55
51
-
* hidpi mode will load the image double size for retina displays.
56
+
- hidpi mode will load the image double size for retina displays.
52
57
53
-
* You should provide a full URL to the image, not a relative path.
58
+
- You should provide a full URL to the image, not a relative path.
54
59
55
-
* In case you're using Statically (ie: the default) and there's no supported extension (gif, jpg, jpeg, png, or webp) listed in the image path, then the component will render the original, unoptimised version (https://twitter.com/staticallyio/status/1405700757475663873). You may be able to work around this by adding an ignored query (eg: `&image.jpg`) to the end of the URL or somewhere in the path, but results may vary. For example, https://pbs.twimg.com/media/FEBzSvdWYAoVJGc?format=jpg&name=medium does not contain '.jpg', and appending `&image.jpg` does not work. However, you can add the .jpg after the ID: `https://pbs.twimg.com/media/FEBzSvdWYAoVJGc.jpg?format=jpg&name=medium`. This will vary depending on the origin.
60
+
- In case you're using Statically (ie: the default) and there's no supported extension (gif, jpg, jpeg, png, or webp) listed in the image path, then the component will render the original, unoptimised version (https://twitter.com/staticallyio/status/1405700757475663873). You may be able to work around this by adding an ignored query (eg: `&image.jpg`) to the end of the URL or somewhere in the path, but results may vary. For example, https://pbs.twimg.com/media/FEBzSvdWYAoVJGc?format=jpg&name=medium does not contain '.jpg', and appending `&image.jpg` does not work. However, you can add the .jpg after the ID: `https://pbs.twimg.com/media/FEBzSvdWYAoVJGc.jpg?format=jpg&name=medium`. This will vary depending on the origin.
56
61
57
62
## Aspect Ratio
63
+
58
64
Don't know exactly what aspect ratio your container will have when it loads on a user's screen? Use `bind:clientWidth` and `bind:clientHeight` to calculate the aspect ratio:
59
65
60
66
```
@@ -71,20 +77,20 @@ Don't know exactly what aspect ratio your container will have when it loads on a
71
77
72
78
## Have full control of your server?
73
79
74
-
Then this might not be the best package for you.
80
+
Then this might not be the best package for you.
75
81
76
82
This component is more suitable if you:
77
83
78
-
* don't have a server
79
-
* don't have storage space/processing power on the server
80
-
* need images to be cropped/resized/whatever at runtime rather than at buildtime
81
-
* want something that works with SvelteKit
82
-
* don't have a CDN in place already
84
+
- don't have a server
85
+
- don't have storage space/processing power on the server
86
+
- need images to be cropped/resized/whatever at runtime rather than at buildtime
87
+
- want something that works with SvelteKit
88
+
- don't have a CDN in place already
83
89
84
90
If you:
85
91
86
-
* have a CDN in place
87
-
* need more finegrained control over image processing
88
-
* don't want third parties interfering with your images
92
+
- have a CDN in place
93
+
- need more finegrained control over image processing
94
+
- don't want third parties interfering with your images
89
95
90
96
You might instead want to check out https://github.com/matyunya/svelte-image
0 commit comments