A Go vector graphics library that renders to SVG, PDF, raster images, HTML Canvas, and more with advanced text and path operations.
Canvas is a vector graphics library written in Go that provides a unified API for rendering to multiple formats including SVG, PDF, raster images, and HTML Canvas. It solves the problem of generating high-quality vector graphics with advanced text layout and precise path operations in Go applications.
Go developers needing to generate vector graphics, PDFs, or complex text layouts, such as those building charting libraries, document generators, or graphics-intensive applications.
Developers choose Canvas for its numerically stable path operations, multi-format output from a single API, and production-ready performance with optimized rasterization, making it a robust alternative to C-based libraries like Cairo.
Vector graphics in Go
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Outputs to SVG, PDF, EPS, raster images, HTML Canvas via WASM, and more from a single API, as shown in the README's feature list and examples like the HTML Canvas demo.
Uses HarfBuzz for shaping, FriBidi for bidirectionality, and Knuth's algorithm for line breaking, supporting mixed scripts and fonts, evidenced by the text formatting examples in Figure 1.
Provides numerically stable boolean operations (AND, OR, XOR, etc.) with O((n+k) log n) complexity, tested extensively with degenerate data like OpenStreetMap shapes.
Features an ASM-optimized rasterizer that benchmarks show is at least twice as fast as alternatives like Cairo in extreme cases, per the README's performance discussion.
Recent changes in the README, such as renamed methods and parameter adjustments, indicate breaking updates that can disrupt existing codebases.
The author admits the library's vast scope and complexity likely hide bugs, with coverage still lacking despite unit and fuzz tests.
Optimal performance with HarfBuzz and FriBidi requires CGO, which complicates cross-compilation and adds external dependencies.
canvas is an open-source alternative to the following products:
node-canvas is a Cairo-backed Canvas implementation for Node.js that allows server-side generation of images and graphics using the HTML5 Canvas API.
Cairo is a 2D graphics library that provides vector drawing capabilities with support for multiple output targets including screen, PDF, and SVG.