@@ -79,7 +79,10 @@ Use the image in the template as a component:
79
79
80
80
#### Result
81
81
82
- This script will generate the following ` <img> ` element :
82
+ This script will generate the following ` <img> ` element with the following optimizations :
83
+
84
+ - Quality = 75
85
+ - Format = .webp
83
86
84
87
` ` ` tsx
85
88
<img
@@ -125,7 +128,76 @@ export default component$(() => {
125
128
);
126
129
});
127
130
` ` `
131
+ #### Customize image format
132
+ Images are automatically converted to ` .webp ` format , but you can also specify the format manually :
133
+ Available formats :
134
+
135
+ <div class = " docs-long-list" >
136
+ - `heic`
137
+ - `heif`
138
+ - `avif`
139
+ - `jpeg`
140
+ - `jpg`
141
+ - `jpe`
142
+ - `tile`
143
+ - `dz`
144
+ - `png`
145
+ - `raw`
146
+ - `tiff`
147
+ - `tif`
148
+ - `webp`
149
+ - `gif`
150
+ - `jp2`
151
+ - `jpx`
152
+ - `j2k`
153
+ - `j2c`
154
+ - `jxl`
155
+ </div >
156
+
157
+ Supported file formats to be converted are :
158
+ <div class = " docs-long-list" >
159
+ - `jpg`
160
+ - `jpeg`
161
+ - `png`
162
+ - `webp`
163
+ - `gif`
164
+ - `tiff`
165
+ - `avif`
166
+ </div >
167
+
168
+ In the below example , a ` jpg ` image is converted to a ` png ` format :
128
169
170
+ ` ` ` tsx
171
+ import { component$ } from '@builder.io/qwik';
172
+ import Image from '~/media/your_image.jpg?format=png&jsx';
173
+
174
+ export default component$(() => {
175
+ return (
176
+ <div>
177
+ <Image />
178
+ </div>
179
+ );
180
+ });
181
+ ` ` `
182
+
183
+ #### Customize image quality
184
+ As noted above , the default quality is set to 75 , but you can also specify the quality manually .
185
+
186
+ Quality parameter is an integer between 1 and 100.
187
+
188
+ ` ` ` tsx
189
+ import { component$ } from '@builder.io/qwik';
190
+ import Image from '~/media/your_image.png?quality=100&jsx';
191
+
192
+ export default component$(() => {
193
+ return (
194
+ <div>
195
+ <Image />
196
+ </div>
197
+ );
198
+ });
199
+
200
+ ` ` `
129
201
130
202
#### Customize image ` width ` and ` height `
131
203
@@ -176,6 +248,24 @@ export default component$(() => {
176
248
}
177
249
` ` `
178
250
251
+ #### Image Optimization for SVGs
252
+ <abbr title = " Scalable Vector Graphics" >SVGs</abbr > can be added directly to your JSX code , but you can also use the image optimization approach to optimize them :
253
+
254
+ ` ` ` tsx
255
+ import { component$ } from '@builder.io/qwik';
256
+ import SvgImage from '~/media/your_image.svg?jsx';
257
+
258
+ export default component$(() => {
259
+ return (
260
+ <>
261
+ <h1>Image Example</h1>
262
+ <div class="image-wrapper" >
263
+ <SvgImage />
264
+ </div>
265
+ </>
266
+ );
267
+ });
268
+ ` ` `
179
269
## ` @unpic/qwik `
180
270
181
271
- Site with detailed instructions on usage : [@unpic / qwik ](https :// unpic.pics/img/qwik/)
0 commit comments