# image/write
Encode an image and write it to a file. The format comes from the path
extension (`.jpg`/`.jpeg`/`.png`/`.webp`) when recognised, otherwise the
image's output format is used.
## Syntax
[image/write $img $path ?opts]
## Parameters
- `$img` — an `Image` value
- `$path` — destination path (string)
- `$opts` — optional map; `:quality` and `:compression-level` as for
`image/bytes`
## Examples
set img [image/open "test/fixtures/images/test.png"] [image/write $img "/tmp/out.png"] # → 115 (bytes written, fixture) [image/write $img "/tmp/out.jpg"] # writes jpeg (extension wins) [image/write $img "/tmp/out.bin"] # unknown ext → image's out-format
## Returns
The number of bytes written. `%Err{:message}` when `$path` is missing or not
a string; `nil` when `$img` is not an `Image`, encoding fails, or the file
cannot be written. The written count equals
`[bytes/len [unwrap [fs/read $path]]]` (image bytes may not be valid UTF-8).
## See Also
`image/bytes`, `image/encode`, `image/open`, `fs/write`