---
title: "oneimage-go"
url: https://recursiveai.org/oneimage/go/docs/overview/
description: "The module README: what oneimage for Go is, its packages, the two API layers, safety on hostile input, determinism, conformance counts and speed."
version: "1.0.0"
source: https://github.com/recursive-ai-oss/oneimage-go/blob/b7d64a3cb3d7b2c0196aeab4bb0f8daf249d68a7/README.md
---

# oneimage-go

Zero third-party dependencies: oneimage-go depends only on the Go standard library and Recursive AI's own pure-Go
modules (onefont and onepdf), with no cgo and no `unsafe`.

A pure-Go image library: decode and encode PNG, JPEG, GIF, WebP, BMP, ICO and TIFF; colour management with ICC
profiles; resize, filters, drawing and compositing; SVG, rich text, Photoshop files, Windows metafiles and PDF pages
rendered to pixels. Every codec and the compression underneath it is written here, and only the standard library's
`image`, `image/color`, `image/draw` and `io` types are used for interop.

```go
package main

import (
	"log"
	"os"

	"recursiveai.org/go/oneimage"
	"recursiveai.org/go/oneimage/pdf"
)

func main() {
	photo, err := os.Open("photo.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer photo.Close()
	thumb, err := oneimage.Thumbnail(photo, 400, 400) // decoded small, fitted, upright
	if err != nil {
		log.Fatal(err)
	}
	out, err := os.Create("thumb.webp")
	if err != nil {
		log.Fatal(err)
	}
	defer out.Close()
	if err := oneimage.EncodeWebP(out, thumb, &oneimage.WebPOptions{Quality: 80}); err != nil {
		log.Fatal(err)
	}

	report, err := os.Open("report.pdf")
	if err != nil {
		log.Fatal(err)
	}
	defer report.Close()
	page, err := pdf.RenderPage(report, 0, pdf.WithDPI(150)) // page 1 at 150 dpi
	if err != nil {
		log.Fatal(err)
	}
	png, err := os.Create("page1.png")
	if err != nil {
		log.Fatal(err)
	}
	defer png.Close()
	if err := oneimage.EncodePNG(png, page, nil); err != nil {
		log.Fatal(err)
	}
}
```

That program is run by the tests (`Example_readme` in `readme_test.go`), and a test keeps it identical to this one.

```
go get recursiveai.org/go/oneimage
```

Go 1.24 or newer. It builds from the module proxy alone, with no workspace or replace directives; the only
modules it requires are our own: `recursiveai.org/go/onefont` v1.2.0 and `recursiveai.org/go/onepdf` v1.0.1 (with its
`fonts` module). Licence: MIT OR Apache-2.0, © Recursive AI, LLC.

## What is in it

| Package | What it does |
|---|---|
| `oneimage` | The pixel model (8-bit, 16-bit and float samples; gray, RGB, CMYK, Lab, indexed; straight or premultiplied alpha), the format registry, PNG and APNG, JPEG, GIF, WebP (lossy, lossless, animated), BMP, ICO and CUR, TIFF (classic and BigTIFF); metadata (ICC, Exif, XMP) carried through decode and encode; ICC v2 and v4 colour management; resize, crop, rotate, affine and perspective transforms, tone, filters, effects, dithering and quantizers; drawing with paths, strokes, brushes and blend modes; compositing |
| `oneimage/layers` | Layered documents: pixel, group, fill and adjustment layers with masks, clipping, blend modes and layer styles, rendered tile by tile on demand |
| `oneimage/svg` | SVG: shapes, paths, gradients, patterns, clips, masks, markers, filters, a CSS subset and text, rendered at any output size and for any region |
| `oneimage/text` | Rich text on onefont: shaping, bidi, line breaking, fallback, decorations, text on a path, colour glyphs |
| `oneimage/psd` | Photoshop PSD and PSB: merged image, layers, masks and layer styles, read and written |
| `oneimage/metafile` | Windows EMF, EMF+ and WMF: a command stream and a raster renderer |
| `oneimage/pdf` | PDF pages drawn as rasters on onepdf: vector art, text, images (with JPEG, JPEG 2000 and JBIG2 decoded here), shadings, patterns, transparency, forms |
| `oneimage/web` | A `net/http` middleware that serves resized and converted images from URL commands, with signed URLs, presets, limits and a disk cache with ETag and single-flight |
| `oneimage/stdreg` | A blank import that lets the standard library's `image.Decode` read every format above |

### Two layers, one engine

The happy path is a few calls on `io.Reader` and `io.Writer`: `Decode`, `Identify`, `Thumbnail`, `Convert` and the
`Encode…` functions. Under it is the low layer: a registry of formats with decoders and encoders that take
configurations, region and scale hints, limits and contexts; frames, layers and records as iterators; and operations
as immutable values with names and parameters you can list and serialise. Decoded images implement `image.Image`,
and every encoder and operation accepts any `image.Image`, with fast paths for the standard types.

### Safe on hostile input

Files, SVG documents, fonts and PDFs are treated as untrusted. Dimensions, pixel counts, frame counts, metadata,
expansion ratios and total allocation are limited by defaults you can change, and checked before anything is
allocated; decompression bombs stop at their budget with an error. Parsers never recurse on input depth. The
library imports no `net` or `os/exec` (only `oneimage/web` serves HTTP) and opens no files: input and output are
readers and writers you hand it. Every decoder and parser has fuzz targets.

### Deterministic

The same bytes and options give the same pixels and the same encoded bytes, on any number of goroutines. Lossless
decoders are bit-exact; lossy decoders and float operations stay within one level at 8 bits.

## Conformance

The library is judged by our internal conformance kit, a language-neutral set of
test cases with pixel tolerances, run against adapters for each implementation. oneimage-go passes every case the
C# library (RecursiveAI.OneImage 1.11.2) passes. A *recorded deviation* is a case where oneimage-go differs from the
kit's expectation and the kit records why (a bug, or behaviour the library documents). The counts are those of
oneimage-go at commit 9bb9cc4 against kit commit 7d6eea54.

| Suite | Cases | Passes | Recorded deviations |
|---|---:|---:|---:|
| core | 363 | 362 | 1 |
| decode | 1015 | 1014 | 1 |
| drawing | 268 | 268 | 0 |
| encode | 337 | 337 | 0 |
| icc | 420 | 420 | 0 |
| layers | 164 | 164 | 0 |
| metafile | 464 | 464 | 0 |
| ops | 605 | 605 | 0 |
| pdf | 557 | 556 | 1 |
| psd | 324 | 324 | 0 |
| safety | 398 | 398 | 0 |
| svg | 1857 | 1729 | 128 |
| text | 470 | 470 | 0 |
| web | 140 | 140 | 0 |
| **Total** | **7382** | **7251** | **131** |

## Speed

Medians of five runs on one machine (AMD Ryzen 9 7950X3D, Linux, Go 1.26.8, 8 threads), every row checked for
the same result before it is timed. The comparison is the fastest pure-Go competitor for the task; where there is
none, the C# library at the same degree of parallelism. A ratio under 1 means oneimage-go took less time. Method,
machine records and every row, with allocations: [bench/RESULTS.md](https://github.com/recursive-ai-oss/oneimage-go/blob/b7d64a3cb3d7b2c0196aeab4bb0f8daf249d68a7/bench/RESULTS.md).

| Task | oneimage-go | compared with | time | ratio |
|---|---:|---|---:|---:|
| PNG decode, photo | 27.35 ms | standard library | 53.44 ms | 0.51 |
| PNG encode, photo | 114.52 ms | standard library | 422.65 ms | 0.27 |
| JPEG decode, 24 MP 4:2:0 | 89.54 ms | standard library | 168.14 ms | 0.53 |
| JPEG encode, 24 MP 4:2:0 | 68.41 ms | standard library | 322.02 ms | 0.21 |
| GIF decode | 4.56 ms | standard library | 8.68 ms | 0.53 |
| GIF encode | 8.50 ms | standard library | 12.60 ms | 0.68 |
| WebP decode, lossy photo | 25.14 ms | golang.org/x/image | 32.56 ms | 0.77 |
| WebP encode, lossless photo | 247.50 ms | nativewebp | 447.31 ms | 0.55 |
| WebP encode, lossy 2000×1500 | 39.43 ms | C# library | 49.10 ms | 0.80 |
| BMP decode | 3.68 ms | golang.org/x/image | 3.89 ms | 0.95 |
| TIFF decode, LZW | 7.37 ms | golang.org/x/image | 63.67 ms | 0.12 |
| Thumbnail from a 24 MP JPEG | 66.74 ms | disintegration/imaging | 215.97 ms | 0.31 |
| Resize 6000×4000 to 400 wide, Lanczos3 | 19.49 ms | disintegration/imaging | 39.10 ms | 0.50 |
| Inflate, mixed data | 31.39 ms | standard library | 37.56 ms | 0.84 |
| Deflate level 6, mixed data | 18.96 ms | standard library | 101.12 ms | 0.19 |
| ICC conversion, sRGB to Display P3, 1 MP | 2.12 ms | mandykoh/prism | 9.54 ms | 0.22 |
| ICC conversion, CMYK to sRGB, 4 MP | 7.10 ms | C# library | 17.81 ms | 0.40 |
| SVG render, scene | 5.80 ms | oksvg | 43.54 ms | 0.13 |
| Fill a 1000-point polygon, 2000×2000 | 0.76 ms | fogleman/gg | 7.68 ms | 0.10 |
| Shaped text wrap, 24,000 characters | 3.29 ms | go-text/typesetting | 3.68 ms | 0.89 |
| PSD merged image, 3000×2000 | 3.04 ms | oov/psd | 4.49 ms | 0.68 |
| Metafile render | 5.99 ms | C# library | 6.95 ms | 0.86 |
| Flatten ten 24 MP layers | 34.61 ms | C# library | 40.85 ms | 0.85 |
| PDF vector page, 150 dpi | 48.30 ms | pdfview | 69.99 ms | 0.69 |
| PDF text page, 150 dpi | 13.94 ms | pdfview | 40.61 ms | 0.34 |
| PDF image page, 150 dpi | 74.52 ms | pdfview | 105.62 ms | 0.71 |

The PDF rows time bytes to pixels for page 1 against github.com/richardwilkes/pdfview, which renders a page on
one thread; oneimage-go uses up to 8 workers per page. On one thread (`GOMAXPROCS=1`) the same pages take 169.79 ms,
36.84 ms and 132.78 ms (vector, text, image), so the vector and image pages are slower than pdfview there; the
table in [bench/RESULTS.md](https://github.com/recursive-ai-oss/oneimage-go/blob/b7d64a3cb3d7b2c0196aeab4bb0f8daf249d68a7/bench/RESULTS.md) shows both.

## Where to look next

`go doc recursiveai.org/go/oneimage` and the other packages; every exported identifier states its defaults and
edge behaviour, and the public features have runnable `Example` functions. [CHANGELOG.md](https://recursiveai.org/oneimage/go/docs/changelog/) lists what
each release provides.
