Skip to content

Images

Source: src/Cloudflare/Images/Images.ts

A Cloudflare Images binding for image transformation inside Workers — a Worker-only binding with no backing cloud resource.

Images is a single value that is at once the Binding.Service tag, the callable that produces an ImagesBinding, and the type. Declare it on a Worker’s env (it flows through InferEnvcf.ImagesBinding) or yield* it inside an Effect-native Worker to attach the binding and obtain the ImagesClient.

import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
Cloudflare.Worker("ImageWorker", { main: import.meta.url },
Effect.gen(function* () {
const images = yield* Cloudflare.Images.Images("PIPELINE");
return {
fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
const info = yield* images.info(request.stream);
return yield* HttpServerResponse.json(info);
}),
};
}).pipe(Effect.provide(Cloudflare.Images.ImagesBinding)),
);
export const Worker = Cloudflare.Worker("Worker", {
main: "./src/worker.ts",
env: { MEDIA: Cloudflare.Images.Images("PIPELINE") },
});
export type WorkerEnv = Cloudflare.InferEnv<typeof Worker>;
// { MEDIA: ImagesBinding }