← All libraries

CandyFreeze

📸 CandyFreeze

Code → SVG screenshot generator

port of freeze svg screenshots no-gd ansi

Turn code or terminal output into an SVG screenshot. No ext-gd / Imagick — output is plain text suitable for git diffs and CI artifacts. ANSI SGR (16 / 256 / 24-bit truecolor + bold / italic / underline) becomes <tspan> in the SVG.

Install

composer require sugarcraft/candy-freeze

Quickstart

use SugarCraft\Freeze\SvgRenderer;

$svg = SvgRenderer::dracula()
    ->withLineNumbers(true)
    ->withWindow(true)
    ->withPadding(24)
    ->render($code);

file_put_contents('out.svg', $svg);

// ANSI input is honoured — SGR colours become <tspan> segments.
$svg = SvgRenderer::dark()
    ->render("\x1b[31merror:\x1b[0m something broke");

What's in the box

Pure-PHP SVGNo raster pipeline. The output is a text file — diffable, grep-able.
Window chromemacOS-style traffic-light controls, optional drop shadow, configurable border radius.
Line numbersOptional left-gutter line counter.
Five themesdark, light, dracula, tokyo-night, nord.
ANSI honouredPipe coloured terminal output through; SGR sequences become tspan colour spans.
Per-segment backgroundANSI background colours render as <rect> fills behind text.
LigaturesEnable font-variant-ligatures for code ligature rendering (→, >=, !==, etc.).
Language detectionHeuristic detection from shebang, filename extension, and content signatures.
CLI + librarycandyfreeze input.php -o out.svg, or SvgRenderer::dracula()->render($code).

Source & demos

Try the quickstart →

API

ClassMethodDescription
SvgRendererdracula(), dark(), light(), tokyoNight(), nord()Create renderer with theme
SvgRendererwithLineNumbers(bool)Show line numbers
SvgRendererwithWindow(bool)Show window chrome
SvgRendererwithPadding(pixels)Set padding
SvgRendererwithLigatures(bool)Enable font-variant-ligatures
SvgRendererwithBorderRadius(int)Set corner radius
SvgRendererrender(code)Render code to SVG
LanguageDetectordetect(content)Detect language from content (shebang or signatures)
LanguageDetectordetectFromFilename(filename)Detect language from filename extension
SegmentwithBg(?string)Return segment with different background colour

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

Screenshot

Screenshot

Code → SVG with traffic-light chrome + line numbers.
ANSI input

ANSI input

SGR foreground colors parsed and rendered as colored SVG spans.