Transcode images
Transcode an image from Workers AI before uploading to R2
const stream = await env.AI.run(  "@cf/bytedance/stable-diffusion-xl-lightning",  {    prompt: YOUR_PROMPT_HERE  });
// Convert to AVIFconst image = (  await env.IMAGES.input(stream)    .output({format: "image/avif"})).response();
const fileName = "image.avif";
// Upload to R2await env.R2.put(fileName, image.body);Was this helpful?
- Resources
 - API
 - New to Cloudflare?
 - Products
 - Sponsorships
 - Open Source
 
- Support
 - Help Center
 - System Status
 - Compliance
 - GDPR
 
- Company
 - cloudflare.com
 - Our team
 - Careers
 
- 2025 Cloudflare, Inc.
 - Privacy Policy
 - Terms of Use
 - Report Security Issues
 - Trademark