Skip to content

Commit 52a8c5e

Browse files
authored
docs(integrations): improve image optimization page (#7423)
* docs: add image format section * style: add long list flex wrap for file formats * docs: add customize image quality section * docs: add SVG section * docs improve image quality section
1 parent 7d9ed00 commit 52a8c5e

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

packages/docs/src/routes/docs/docs.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,14 @@ pre {
272272
border-radius: 5px;
273273
overflow: hidden;
274274
}
275+
276+
.docs-long-list {
277+
display: flex;
278+
flex-wrap: wrap;
279+
& ul {
280+
display: contents;
281+
& li {
282+
list-style-type: none;
283+
}
284+
}
285+
}

packages/docs/src/routes/docs/integrations/image-optimization/index.mdx

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ Use the image in the template as a component:
7979

8080
#### Result
8181

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
8386

8487
```tsx
8588
<img
@@ -125,7 +128,76 @@ export default component$(() => {
125128
);
126129
});
127130
```
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:
128169

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+
```
129201

130202
#### Customize image `width` and `height`
131203

@@ -176,6 +248,24 @@ export default component$(() => {
176248
}
177249
```
178250

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+
```
179269
## `@unpic/qwik`
180270

181271
- Site with detailed instructions on usage: [@unpic/qwik](https://unpic.pics/img/qwik/)

0 commit comments

Comments
 (0)