# image/bytes
Encode an image to bytes using its output format — the source format by
default, or the format set by `image/jpeg` / `image/png` / `image/webp`.
## Syntax
[image/bytes $img ?opts]
## Parameters
- `$img` — an `Image` value
- `$opts` — optional map; `:quality` 1–100 (jpeg/webp) and
`:compression-level` 0–9 (png). Defaults come from the image's current
settings; values are clamped, not errors.
## Examples
set img [image/open "test/fixtures/images/test.jpg"] [image/bytes $img] # → jpeg bytes (source format) set png [image/png $img] [image/format [image/decode [image/bytes $png]]] # → "png"
## Returns
A binary-safe string of encoded bytes, or `nil` when the argument is not a
live `Image` or the encoder fails.
## See Also
`image/encode`, `image/write`, `image/base64`, `image/format`