Skip to content

Commit 3c3abd0

Browse files
committed
Adding face cropping parameters to image transformation
1 parent d4cce74 commit 3c3abd0

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

src/content/docs/images/transform-images/transform-via-url.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ You must specify at least one option. Options are comma-separated (spaces are no
135135

136136
<Render file="width" />
137137

138+
### `zoom`
139+
140+
<Render file="zoom" />
141+
138142
## Recommended image sizes
139143

140144
Ideally, image sizes should match exactly the size they are displayed on the page. If the page contains thumbnails with markup such as `<img width="200" …>`, then images should be resized to `width=200`. If the exact size is not known ahead of time, use the [responsive images technique](/images/manage-images/create-variants/).

src/content/docs/images/transform-images/transform-via-workers.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ The `fetch()` function accepts parameters in the second argument inside the `{cf
118118

119119
<Render file="width" />
120120

121+
### `zoom`
122+
123+
<Render file="zoom" />
124+
121125
In your worker, where you would fetch the image using `fetch(request)`, add options like in the following example:
122126

123127
```js
@@ -281,4 +285,4 @@ When testing image resizing, please deploy the script first. Resizing will not b
281285

282286
Resized images are always cached. They are cached as additional variants under a cache entry for the URL of the full-size source image in the `fetch` subrequest. Do not worry about using many different Workers or many external URLs — they do not influence caching of resized images, and you do not need to do anything for resized images to be cached correctly.
283287

284-
If you use the `cacheKey` fetch option to unify caches of multiple different source URLs, you must not add any resizing options to the `cacheKey`, as this will fragment the cache and hurt caching performance. The `cacheKey` option is meant for the full-size source image URL only, not for its resized variants.
288+
If you use the `cacheKey` fetch option to unify caches of multiple different source URLs, you must not add any resizing options to the `cacheKey`, as this will fragment the cache and hurt caching performance. The `cacheKey` option is meant for the full-size source image URL only, not for its resized variants.

src/content/partials/images/gravity.mdx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ When cropping with `fit: "cover"` and `fit: "crop"`, this parameter defines the
1717
You must subtract the height of the image before you calculate the focal point.
1818
:::
1919

20+
- `face`\
21+
Selects focal point based on face detection (with minimum bounding box surounding all faces within the image). Only works with `fit: "crop"` and falls back to the center of the image as focalpoint if face(s) are not found.
22+
2023
<Tabs>
2124
<TabItem label="URL format">
2225
```js
@@ -29,6 +32,10 @@ You must subtract the height of the image before you calculate the focal point.
2932
OR
3033

3134
gravity=0x1
35+
36+
OR
37+
38+
gravity=face
3239
```
3340

3441
</TabItem>
@@ -43,6 +50,10 @@ You must subtract the height of the image before you calculate the focal point.
4350
OR
4451

4552
g=0x1
53+
54+
OR
55+
56+
g=face
4657
```
4758

4859
</TabItem>
@@ -58,7 +69,10 @@ OR
5869

5970
cf: {image: {gravity: {x:0.5, y:0.2}}}
6071

72+
OR
73+
74+
cf: {image: {gravity: "face"}}
6175
```
6276
</TabItem>
6377
</Tabs>
64-
```
78+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
{}
3+
---
4+
import { Tabs, TabItem } from "~/components"
5+
6+
Used alongside `gravity: "face"` and `fit: "crop"` to control the zoom level.
7+
8+
Valid options range from 0 to 1 where 0 should return the entire image and 1 should return only the face.
9+
Only takes effect if face(s) are found.
10+
11+
<Tabs>
12+
<TabItem label="URL format">
13+
```js
14+
zoom=0.1
15+
```
16+
</TabItem>
17+
<TabItem label="URL format alias">
18+
```js
19+
zoom=0.2
20+
OR
21+
22+
face-zoom=0.2
23+
```
24+
</TabItem>
25+
<TabItem label="Workers">
26+
```js
27+
cf: {image: {zoom: 0.5}}
28+
```
29+
</TabItem>
30+
</Tabs>

0 commit comments

Comments
 (0)