# oneimage Go docs, all pages (oneimage-go 1.0.0) Every page of https://recursiveai.org/oneimage/go/docs/ as markdown, getting started first. Index: https://recursiveai.org/oneimage/go/llms.txt # Getting started with oneimage for Go Install oneimage for Go, make a WebP thumbnail from a JPEG and a PNG from a PDF page, then decode, resize, sharpen and encode an image, convert in one call, and check for input that isn’t an image. oneimage for Go is a pure-Go image library: PNG, JPEG, GIF, WebP, BMP, ICO and TIFF decoded and encoded by its own codecs, with ICC color management, resize, filters, drawing and compositing, and SVG, rich text, Photoshop files, Windows metafiles and PDF pages rendered to pixels. Every sample on this page was run with Go 1.26.8 against `recursiveai.org/go/oneimage` v1.0.0 from the Go module proxy; the output under each one is what it printed, and the images are the files it wrote. ## Install oneimage needs Go 1.24 or newer. ```sh mkdir thumbs && cd thumbs go mod init example.com/thumbs go get recursiveai.org/go/oneimage@v1.0.0 ``` The license is MIT or Apache-2.0, at your choice. There is no cgo and no `unsafe`. The only modules it requires are Recursive AI’s own pure-Go `recursiveai.org/go/onefont` v1.2.0 and `recursiveai.org/go/onepdf` v1.0.1 (with its `fonts` module). ## A thumbnail and a PDF page The README’s program, saved as `main.go`. It reads `photo.jpg` and `report.pdf` from the current folder; here they were NASA’s Apollo 17 photograph of Earth (1920 × 1920) and the IRS Form W-9. ```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) } } ``` The `pdf` package pulls in onepdf, so run `go mod tidy` once to record its modules, then run the program: ```sh go mod tidy go run . ``` It prints nothing and writes two files: `thumb.webp`, 400 × 400 and 21 KB, and `page1.png`, 1275 × 1650 and 282 KB. ![thumb.webp: the Apollo 17 photograph of Earth, Africa and Antarctica under swirls of cloud, on black, 400 × 400](https://recursiveai.org/oneimage/go/images/thumb.webp) ![page1.png: page 1 of Form W-9, “Request for Taxpayer Identification Number and Certification”, with its boxes, checkboxes and small print, rendered at 150 dpi](https://recursiveai.org/oneimage/go/images/page1.png) `Thumbnail` decodes the JPEG at a reduced size when it can, fits it inside the box and turns it upright by its Exif orientation. `RenderPage` takes a zero-based page index. ## Decode, edit, encode In a new module (`go mod init example.com/edit` and the same `go get`), with `photo.jpg` next to `main.go`: ```go package main import ( "bytes" "errors" "fmt" "log" "os" "recursiveai.org/go/oneimage" ) func main() { data, err := os.ReadFile("photo.jpg") if err != nil { log.Fatal(err) } // Size and metadata, without decoding pixels. info, err := oneimage.Identify(bytes.NewReader(data)) if err != nil { log.Fatal(err) } fmt.Printf("photo.jpg: %s, %dx%d, %d-bit\n", info.Format, info.Width, info.Height, info.BitDepth) // Decode, resize to 800 px wide, sharpen. img, err := oneimage.Decode(bytes.NewReader(data)) if err != nil { log.Fatal(err) } ops := []oneimage.Op{ oneimage.Resize(800, 0), oneimage.Sharpen(0.6, 1, 0), } small, err := oneimage.Apply(img, ops...) if err != nil { log.Fatal(err) } steps, _ := oneimage.Describe(img, ops...) for _, s := range steps { fmt.Println(s) } // Encode as JPEG. out, err := os.Create("photo-800.jpg") if err != nil { log.Fatal(err) } defer out.Close() if err := oneimage.EncodeJPEG(out, small, &oneimage.JPEGOptions{Quality: 85}); err != nil { log.Fatal(err) } // Decode, edit and encode in one call. gray, err := os.Create("photo-gray.webp") if err != nil { log.Fatal(err) } defer gray.Close() err = oneimage.Convert(gray, "webp", bytes.NewReader(data), oneimage.Resize(400, 0), oneimage.Grayscale()) if err != nil { log.Fatal(err) } // Bytes that aren't an image. _, err = oneimage.Decode(bytes.NewReader([]byte("not an image"))) fmt.Println(err) fmt.Println(errors.Is(err, oneimage.ErrFormat)) } ``` ```sh go run . ``` ```text photo.jpg: jpeg, 1920x1920, 8-bit sharpen(amount=0.6, radius=1, threshold=0, linear=True, edge=clamp) -> 800x800 resize(width=800, height=0, fit=contain, anchor=center, upscale=True, filter=auto, linear=True, background=[0, 0, 0, 0]) -> 800x800 decode(format=jpeg, frames=1) -> 1920x1920 oneimage: unrecognised image format true ``` It wrote `photo-800.jpg` (800 × 800, 118 KB) and `photo-gray.webp` (400 × 400, 17 KB): ![photo-800.jpg: the Earth photograph resized to 800 × 800 and sharpened](https://recursiveai.org/oneimage/go/images/photo-800.jpg) ![photo-gray.webp: the Earth photograph at 400 × 400 in grayscale](https://recursiveai.org/oneimage/go/images/photo-gray.webp) - `Identify` reads the size and metadata from the header without decoding pixels. - `Decode` detects the format from the first bytes and returns an `*Image`, which implements `image.Image`. - `Resize(800, 0)` leaves the height free, so the aspect ratio is kept. Resizing is done in linear light by default. - Operations are values. `Apply` runs them in order and never changes its input. `Describe` lists what ran, last operation first, with each result’s size. - `Convert` decodes, applies operations and encodes to the format you name. - Errors are values: `errors.Is` matches `ErrFormat`, `ErrLimit`, `ErrUnsupported` and `ErrOperation`. Every encoder and operation accepts any `image.Image`, so pixels from the standard library or another package go straight in. A blank import of `recursiveai.org/go/oneimage/stdreg` makes the standard library’s `image.Decode` read every format oneimage does. ## Next - [Overview](https://recursiveai.org/oneimage/go/docs/overview/): the module README, with every package, safety limits, conformance counts and speed. - [Changelog](https://recursiveai.org/oneimage/go/docs/changelog/): what is in 1.0.0. - [Package reference on pkg.go.dev](https://pkg.go.dev/recursiveai.org/go/oneimage). # 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. # Changelog All notable changes are listed here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and versions follow [Semantic Versioning](https://semver.org/). ## [1.0.0] - 2026-12-05 The first release. Zero third-party dependencies: it depends only on the Go standard library and Recursive AI's own pure-Go modules (`onefont` v1.2.0, `onepdf` v1.0.1 and `onepdf/fonts` v1.0.1), with no cgo, and builds from the module proxy with no workspace. ### Added - **Pixel model.** `Pixmap`, a rectangle of interleaved samples in one `PixelFormat`: gray, RGB, CMYK, Lab and indexed colour; 8-bit, 16-bit, half-float and 32-bit float samples; no, straight or premultiplied alpha. It implements `image.Image` and `draw.Image`; `FromImage` shares the samples of the standard types. `Image` holds frames with delays, a loop count and metadata (ICC profile, Exif, XMP, text), carried through decode and encode. - **Formats.** Decoders and encoders, all written for this library, for PNG and APNG (every colour type and depth, Adam7, palette quantizer, compression levels and filters), JPEG (baseline, progressive, arithmetic-coded, 12-bit, CMYK and YCCK, restart markers, decoding at reduced size, optimised Huffman tables), GIF (animation, disposal, transparency, Wu and octree quantizers, sixteen dithers), WebP (lossy, lossless, alpha, animation), BMP, ICO and CUR, and TIFF (classic and BigTIFF, strips and tiles, none, LZW, Deflate, PackBits, JPEG and CCITT fax compression, predictors, 1 to 32-bit samples, multi-page). Our own deflate, inflate, LZW, Huffman and arithmetic coders sit underneath them. - **API in two layers.** The happy path is `Decode`, `Identify`, `Open`, `Thumbnail`, `Convert` and the `Encode…` functions on `io.Reader` and `io.Writer`, with `Context` twins. Below it, a format registry (`RegisterFormat`) with decoders and encoders that take region, scale and render-size hints, limits and parallelism; frames and layers as iterators; immutable operation values with names and parameters (`Op`, `Apply`, `Describe`). Errors are values matching `ErrFormat`, `ErrLimit`, `ErrUnsupported` and `ErrOperation`. - **Colour management.** ICC v2 and v4 profiles (matrix/TRC, gray, and lut8, lut16, lutAToB and lutBToA tables), the four rendering intents, black point compensation, a reusable cached `ColorTransform`, built-in sRGB, Display P3, Adobe RGB-compatible, ProPhoto, Rec. 2020, gray and generic CMYK profiles. - **Operations.** Resize with seven filters and fit modes, crop, pad, trim, rotate, flip, orientation, affine and perspective transforms; tone (levels, curves, gamma, exposure, hue and saturation, channel mixer, colour matrices, grayscale, posterize, threshold); Gaussian, box, median, sharpen, convolution, edge detection and other filters and effects; dithering and quantizers; histogram, statistics and equalisation; boolean path operations. - **Drawing and compositing.** Paths, strokes with caps, joins and dashes, solid, gradient, pattern and image brushes, 24 blend modes and the Porter-Duff operators, clipping. - **`oneimage/layers`.** Layered documents with pixel, group, fill and adjustment layers, masks, clipping and layer styles, rendered on demand tile by tile. - **`oneimage/svg`.** An SVG renderer with a bounded XML parser and CSS subset, paint servers, clips, masks, markers, filters and text, drawing at any size and region; nothing outside the document is opened. - **`oneimage/text`.** Rich text on onefont: OpenType shaping, bidi, line breaking, fallback, decorations, text on a path, vertical layout, hinting and colour glyphs. - **`oneimage/psd`.** Photoshop PSD and PSB reading and writing: merged image, layers, masks, layer styles, fill and adjustment layers. - **`oneimage/metafile`.** EMF, EMF+ and WMF: a drawing-command stream and a raster renderer. - **`oneimage/pdf`.** PDF pages drawn as rasters on onepdf: paths, text, images with JPEG, JPEG 2000 and JBIG2 decoders of our own, shadings, patterns, transparency groups, soft masks, blend modes, annotations and forms; registered as the `pdf` format. - **`oneimage/web`.** A `net/http` middleware that serves resized and converted images from URL commands, with HMAC-signed URLs, presets, source limits and a disk cache with ETag and single-flight processing. - **`oneimage/stdreg`.** A blank import that makes the standard library's `image.Decode` read every format. - **Safety.** Limits on pixels, dimensions, frames, metadata, expansion ratio and allocation, checked before allocating and settable per call; explicit stacks instead of recursion; no `unsafe`, no `net` or `os/exec` outside `oneimage/web`, no file access. Fuzz targets for every decoder and parser. - **Determinism.** Identical input and options give identical pixels and encoded bytes at any parallelism. - **Conformance and benchmarks.** The library passes our internal conformance kit as recorded in the README, and `bench/` holds the speed rows against the standard library, golang.org/x/image, disintegration/imaging and the other Go libraries, with the C# library as the floor where no Go library does the task.