cloudflare-demos

images Images

Inspect / resize / convert images — source on GitHub

src/index.ts
import { Hono } from 'hono'

const app = new Hono<{ Bindings: Env }>()

app.post('/info', async (c) => {
  if (!c.req.raw.body) {
    return c.text('image body required', 400)
  }
  return c.json(await c.env.IMAGES.info(c.req.raw.body))
})

app.post('/resize', async (c) => {
  if (!c.req.raw.body) {
    return c.text('image body required', 400)
  }
  const width = Number(c.req.query('width') ?? 200)
  const result = await c.env.IMAGES.input(c.req.raw.body)
    .transform({ width })
    .output({ format: 'image/png' })
  return result.response()
})

export default app
Try it — requests go to a Dynamic Worker running this code. State is isolated per browser session and expires after a while.
response will appear here
response