Skip to content

Commit d288aed

Browse files
authored
fix: wrap Images binding examples in <WranglerConfig> (#21365)
Co-authored-by: Jacob Hands <[email protected]>
1 parent 2aca7fb commit d288aed

File tree

3 files changed

+44
-25
lines changed

3 files changed

+44
-25
lines changed

src/content/changelog/images/2025-02-21-images-bindings-in-workers.mdx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,40 @@ description: >
55
date: 2025-02-24T12:00:00Z
66
---
77

8+
import { WranglerConfig } from "~/components";
9+
810
You can now [interact with the Images API](/images/transform-images/bindings/) directly in your Worker.
911

1012
This allows more fine-grained control over transformation request flows and cache behavior. For example, you can resize, manipulate, and overlay images without requiring them to be accessible through a URL.
1113

1214
The Images binding can be configured in the Cloudflare dashboard for your Worker or in the `wrangler.toml` file in your project's directory:
1315

14-
``` toml
15-
[images]
16-
binding = "IMAGES" # i.e. available in your Worker on env.IMAGES
16+
<WranglerConfig>
17+
18+
```jsonc
19+
{
20+
"images": {
21+
"binding": "IMAGES", // i.e. available in your Worker on env.IMAGES
22+
},
23+
}
1724
```
1825

26+
</WranglerConfig>
27+
1928
Within your Worker code, you can interact with this binding by using `env.IMAGES`.
2029

2130
Here's how you can rotate, resize, and blur an image, then output the image as AVIF:
2231

2332
```ts
24-
​​const info = await env.IMAGES.info(stream);
33+
const info = await env.IMAGES.info(stream);
2534
// stream contains a valid image, and width/height is available on the info object
2635

2736
const response = (
28-
await env.IMAGES.input(stream)
29-
.transform({ rotate: 90 })
30-
.transform({ width: 128 })
31-
.transform({ blur: 20 })
32-
.output({ format: "image/avif" }
33-
)
37+
await env.IMAGES.input(stream)
38+
.transform({ rotate: 90 })
39+
.transform({ width: 128 })
40+
.transform({ blur: 20 })
41+
.output({ format: "image/avif" })
3442
).response();
3543

3644
return response;

src/content/docs/images/transform-images/bindings.mdx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ sidebar:
55
order: 4
66
---
77

8+
import { WranglerConfig } from "~/components";
9+
810
A [binding](/workers/runtime-apis/bindings/) connects your [Worker](/workers/) to external resources on the Developer Platform, like [Images](/images/transform-images/transform-via-workers/), [R2 buckets](/r2/buckets/), or [KV Namespaces](/kv/concepts/kv-namespaces/).
911

1012
You can bind the Images API to your Worker to transform, resize, and encode images without requiring them to be accessible through a URL.
@@ -25,12 +27,18 @@ You can define variables in the `wrangler.toml` file of your Worker project's di
2527

2628
To bind Images to your Worker, add the following to the end of your `wrangler.toml` file:
2729

30+
<WranglerConfig>
2831

29-
```txt
30-
[images]
31-
binding = "IMAGES" # i.e. available in your Worker on env.IMAGES
32+
```jsonc
33+
{
34+
"images": {
35+
"binding": "IMAGES", // i.e. available in your Worker on env.IMAGES
36+
},
37+
}
3238
```
3339

40+
</WranglerConfig>
41+
3442
Within your Worker code, you can interact with this binding by using `env.IMAGES.input()` to build an object that can manipulate the image (passed as a `ReadableStream`).
3543

3644
## Methods
@@ -69,28 +77,28 @@ return response;
6977

7078
### `.output()`
7179

72-
* Defines the [output format](/images/transform-images/) for the transformed image such as AVIF, WebP, and JPEG.
80+
- Defines the [output format](/images/transform-images/) for the transformed image such as AVIF, WebP, and JPEG.
7381

7482
For example, to rotate, resize, and blur an image, then output the image as AVIF:
7583

7684
```ts
7785
const info = await env.IMAGES.info(stream);
7886
// stream contains a valid image, and width/height is available on the info object
79-
87+
8088
const response = (
81-
await env.IMAGES.input(stream)
82-
.transform({ rotate: 90 })
83-
.transform({ width: 128 })
84-
.transform({ blur: 20 })
85-
.output({ format: "image/avif" })
89+
await env.IMAGES.input(stream)
90+
.transform({ rotate: 90 })
91+
.transform({ width: 128 })
92+
.transform({ blur: 20 })
93+
.output({ format: "image/avif" })
8694
).response();
87-
95+
8896
return response;
8997
```
9098

9199
### `.info()`
92100

93-
- Outputs information about the image, such as `format`, `fileSize`, `width`, and `height`.
101+
- Outputs information about the image, such as `format`, `fileSize`, `width`, and `height`.
94102

95103
Responses from the Images binding are not automatically cached. Workers lets you interact directly with the Cache API to customize cache behavior using Workers. You can implement logic in your script to store transformations in Cloudflare’s cache.
96104

src/content/docs/workers/wrangler/configuration.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,12 @@ To bind Images to your Worker, assign an array of the below object to the `image
658658

659659
<WranglerConfig>
660660

661-
```toml title="wrangler.toml"
662-
[[images]]
663-
binding = "IMAGES" # i.e. available in your Worker on env.IMAGES
661+
```jsonc
662+
{
663+
"images": {
664+
"binding": "IMAGES", // i.e. available in your Worker on env.IMAGES
665+
},
666+
}
664667
```
665668

666669
</WranglerConfig>

0 commit comments

Comments
 (0)