All 22 apps

CandyCodeshot

Code → SVG/PNG screenshot generator

inspired by charmbracelet/freeze svg screenshots ansi

CandyCodeshot code coverage

Turn code or terminal output into an SVG or PNG screenshot. The one base requirement is ext-mbstring; the SVG path needs no raster extension (no ext-gd, no Imagick) — plain text output suitable for git diffs and CI artifacts; PNG renders through ext-gd. ANSI SGR (16 / 256 / 24-bit truecolor + bold / italic / underline) becomes per-segment <text> color and font attributes plus <rect> background bands in the SVG; the PNG canvas paints the same foreground colors and background bands.

Install

composer require sugarcraft/candy-codeshot

Quickstart

use SugarCraft\CodeShot\SvgRenderer;

$code = <<<'PHP'
<?php
echo "hello, world\n";
PHP;

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

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

// ANSI input is honoured — SGR colours become per-segment <text> fills
// and <rect> background bands.
$svg = SvgRenderer::dark()
    ->render("\x1b[31merror:\x1b[0m something broke");

What's in the box

Pure-PHP SVGThe SVG path has no raster pipeline — its output is a text file, diffable, grep-able. PNG is a separate renderer behind ext-gd.
Window chromemacOS-style traffic-light controls, optional drop shadow, configurable border radius.
Line numbersOptional left-gutter line counter.
Five themes + file importdark, light, dracula, tokyo-night, nord — or --theme <path.json> / the theme loaders for VS Code and flat-palette files.
ANSI honoredPipe colored terminal output through; SGR sequences become per-segment text colors, bold / italic / underline and background bands.
Per-segment backgroundANSI background colors render as <rect> fills behind text.
Ligatures (SVG only)Enable font-variant-ligatures for code ligature rendering (→, >=, !==, etc.).
Language detectionHeuristic detection from filename extension, then shebang, then content signatures; sixteen grammars get color, other detected names render plain.
CLI + librarycandy-codeshot 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 (0..256; the CLI refuses above 64)
SvgRendererwithShadow(bool) / withBorder(bool)Toggle the drop shadow / the frame outline
SvgRendererwithWindowStyle(string|WindowStyle)Chrome style: macos, windows-terminal, iterm, hyper, none
SvgRendererwithTheme(Theme)Swap the whole palette
SvgRendererwithFont(?string)Embed a TTF/OTF/WOFF/WOFF2 file (library checks existence only; the CLI additionally validates the signature)
SvgRendererwithHighlight(int, int, ?string)Band-highlight lines start..end (SVG only)
SvgRendererwithTitle(string)Set the document's accessible name (child <title> only — no aria-labelledby anchor; not a visual caption)
SvgRendererrender(code)Render code to SVG
PngRendererdark(), light(), dracula(), tokyoNight(), nord(), render(code)GD raster sibling — same fluent surface minus the SVG-only setters; requires ext-gd, and withBorderRadius() is accepted but corners stay square
Themedark(), light(), dracula(), tokyoNight(), nord()Built-in palettes; new Theme(...) for custom colors
VsCodeThemeLoader / FlatPaletteThemeLoaderload(path), fromArray(data)Build a Theme from a VS Code theme or flat JSON palette
CodeHighlighterforTheme(Theme), highlight(code, language)Turn plain code into ANSI-styled tokens using the theme palette
LanguageDetectordetect(content)Detect language from content (shebang or signatures; reads at most 1 MB)
LanguageDetectordetectFromFilename(filename)Detect language from filename extension
SegmentwithBg(?string)Return segment with different background color
FileOutputWriter / StringOutputWriterwrite(chunk), flush(), close() / result()Caller-chunked buffer/forward helpers — library-side only; the renderers return complete bytes and the CLI writes via file_put_contents/echo, never through these

Demos.

VHS-recorded GIF demos of the screenshot and ANSI-pipe flows. Regenerated in CI on pushes to master that change the library.

Code screenshot with macOS window chrome and line numbers

Screenshot

Code → SVG with traffic-light chrome + line numbers.
ANSI-colored error line rendered as colored SVG text

ANSI input

SGR foreground colors parsed and painted on per-segment SVG text.