svg

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package svg provides in-process SVG rasterisation helpers for PDF image embedding. The renderer is intentionally pure Go: it uses oksvg/rasterx for paths and a small text overlay pass for basic <text> elements.

Index

Constants

View Source
const DPIForRaster = 150.0

DPIForRaster is the DPI used when rasterising SVG to PNG for PDF embedding.

View Source
const MaxRasterPixels = 50_000_000

MaxRasterPixels caps the total pixel count of an SVG raster target. The dimensions feeding the rasteriser can be attacker-controlled in untrusted SVG input, so an unbounded image.NewRGBA allocation is a memory risk.

Variables

View Source
var (
	ErrSVGHasZeroDimensions = errors.New("svg has zero dimensions")
	ErrSVGTooLarge          = htmllimits.ErrSVGTooLarge
)

Functions

func MMFromPx

func MMFromPx(px int) float64

MMFromPx converts pixels back to millimetres at DPIForRaster.

func Rasterize

func Rasterize(svgBytes []byte, widthMM, heightMM float64) ([]byte, int, int, error)

Rasterize converts SVG bytes into PNG bytes at the requested mm dimensions using DPIForRaster. When widthMM/heightMM are zero it uses the SVG's viewBox.

func RasterizeWithLimit

func RasterizeWithLimit(svgBytes []byte, widthMM, heightMM float64, maxPixels int64) ([]byte, int, int, error)

RasterizeWithLimit converts SVG bytes into PNG bytes with a custom pixel cap.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL