---
title: "oneimage for Go"
url: https://recursiveai.org/oneimage/go/
description: "A pure-Go image library with its own codecs. Decode and encode PNG, JPEG, GIF, WebP, BMP, ICO and TIFF; resize, filter, draw and composite with ICC color management; render SVG, rich text, PSD, Windows metafiles and PDF pages to pixels. No cgo, no third-party dependencies. MIT or Apache-2.0."
---

# oneimage for Go

A free, open-source image library for Go, MIT or Apache-2.0. It decodes and encodes PNG, JPEG, GIF, WebP, BMP, ICO and TIFF with codecs of its own, and resizes, filters, draws and composites with ICC color management.

Pure Go: no cgo and no third-party dependencies. SVG, rich text, Photoshop files, Windows metafiles and PDF pages render to pixels too.

```sh
go get recursiveai.org/go/oneimage@v1.0.0
```

- [Getting started](https://recursiveai.org/oneimage/go/docs/getting-started/)
- [Docs](https://recursiveai.org/oneimage/go/docs/)
- [GitHub](https://github.com/recursive-ai-oss/oneimage-go)
- [pkg.go.dev](https://pkg.go.dev/recursiveai.org/go/oneimage)

## A thumbnail and a PDF page

The README’s program, run with Go 1.26.8 against v1.0.0 from the module proxy. A 1920 × 1920 JPEG becomes a 400 × 400 WebP thumbnail, and page 1 of a PDF becomes a PNG at 150 dpi.

[Decode, edit and encode](https://recursiveai.org/oneimage/go/docs/getting-started/)

*main.go · 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()
    // decoded small, fitted, upright
    thumb, err := oneimage.Thumbnail(photo, 400, 400)
    if err != nil {
        log.Fatal(err)
    }
    out, err := os.Create("thumb.webp")
    if err != nil {
        log.Fatal(err)
    }
    defer out.Close()
    opts := &oneimage.WebPOptions{Quality: 80}
    if err := oneimage.EncodeWebP(out, thumb, opts); err != nil {
        log.Fatal(err)
    }
 
    report, err := os.Open("report.pdf")
    if err != nil {
        log.Fatal(err)
    }
    defer report.Close()
    // page 1 at 150 dpi
    page, err := pdf.RenderPage(report, 0, pdf.WithDPI(150))
    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)
    }
}
```

*Shell · sh*

```
go mod init example.com/thumbs
go get recursiveai.org/go/oneimage@v1.0.0
go mod tidy
go run .
```

*thumb.webp · 400 × 400, 21 KB*

![NASA’s Apollo 17 photograph of Earth, Africa and Antarctica under swirls of cloud, on black.](https://recursiveai.org/oneimage/go/images/thumb.webp)

*page1.png · 1275 × 1650, 282 KB*

![Page 1 of IRS Form W-9, “Request for Taxpayer Identification Number and Certification”, with its boxes, checkboxes and small print.](https://recursiveai.org/oneimage/go/images/page1.png)

## Speed

From the README at v1.0.0: medians of five runs on an AMD Ryzen 9 7950X3D with Go 1.26.8 on Linux, 8 threads. A ratio under 1 means oneimage took less time.

[Method and machine](https://github.com/recursive-ai-oss/oneimage-go/blob/v1.0.0/README.md#speed)

[Every row](https://github.com/recursive-ai-oss/oneimage-go/blob/v1.0.0/bench/RESULTS.md)

> “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.”
>
> | 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.”
>
> [README.md at v1.0.0](https://github.com/recursive-ai-oss/oneimage-go/blob/v1.0.0/README.md#speed)

## What it does

- **Version**: oneimage v1.0.0. Go 1.24 or newer.
- **Formats**: Decoders and encoders of its own for PNG and APNG, JPEG (baseline, progressive, arithmetic-coded, 12-bit, CMYK), GIF with animation, WebP (lossy, lossless, alpha, animation), BMP, ICO and CUR, and TIFF (classic and BigTIFF, multi-page). Its own deflate, inflate, LZW, Huffman and arithmetic coders sit underneath them.
- **Pixels**: 8-bit, 16-bit, half-float and 32-bit float samples; gray, RGB, CMYK, Lab and indexed color; straight or premultiplied alpha. Decoded images implement `image.Image`, and every encoder and operation accepts any `image.Image`.
- **Metadata**: ICC profiles, Exif and XMP are carried through decode and encode.
- **Color**: ICC v2 and v4 color management with the four rendering intents and black point compensation, and 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, affine and perspective transforms; levels, curves, gamma, hue and saturation, grayscale, threshold; Gaussian, box and median filters, sharpen, convolution and edge detection; dithering, quantizers and histograms.
- **Drawing**: Paths, strokes with caps, joins and dashes, solid, gradient, pattern and image brushes, 24 blend modes, the Porter-Duff operators and clipping.
- **Packages**: `svg` renders SVG at any size and region; `text` lays out rich text with shaping, bidi and color glyphs; `psd` reads and writes Photoshop PSD and PSB; `metafile` renders EMF, EMF+ and WMF; `pdf` draws PDF pages as rasters; `layers` holds layered documents with masks and layer styles.
- **Web**: `oneimage/web` is a `net/http` middleware that serves resized and converted images from URL commands, with signed URLs, presets, limits and a disk cache with ETag.
- **Standard library**: A blank import of `oneimage/stdreg` lets `image.Decode` read every format above.
- **Untrusted input**: Dimensions, pixel counts, frames, metadata, expansion ratios and total allocation are limited by defaults you can change, and checked before anything is allocated. The library opens no files and imports no `net` or `os/exec` outside `oneimage/web`.
- **Output**: The same bytes and options give the same pixels and the same encoded bytes, on any number of goroutines.
- **Dependencies**: No cgo and no `unsafe`. The only modules it requires are Recursive AI’s own `onefont` and `onepdf`.
- **License**: MIT or Apache-2.0, at your choice.
