Skip to content

sugarcraft/candy-freeze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

73 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

candy-freeze

CandyFreeze

CI codecov Packagist Version License PHP

demo

PHP port of charmbracelet/freeze β€” turn code or terminal output into an SVG screenshot. No ext-gd / Imagick required; the output is plain text suitable for git diffs and CI artifacts.

composer require sugarcraft/candy-freeze

CLI

echo "function hello() { return 'world'; }" \
    | candyfreeze --theme dracula --line-numbers > out.svg

candyfreeze input.php \
    --theme tokyo-night --no-window --output screenshot.svg

Flags:

  • --theme {dark|light|dracula|tokyo-night|nord} β€” colour palette.
  • --padding N β€” content padding inside the frame.
  • --no-window β€” drop the macOS-style traffic-light controls.
  • --no-shadow β€” drop the SVG drop-shadow filter.
  • --no-border β€” drop the frame outline.
  • --line-numbers β€” render a left-gutter line counter.
  • --border-radius N β€” corner radius of the frame.
  • -o/--output <path> β€” write SVG to a file instead of stdout.

Library

use SugarCraft\Freeze\SvgRenderer;

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

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

ANSI input is honoured β€” SGR foreground colours (16 / 256 / 24-bit truecolor) plus bold / italic / underline become <tspan> segments in the output. Background colours are rendered as per-segment <rect> fills behind the text.

$svg = SvgRenderer::dark()->render("\x1b[31merror:\x1b[0m something broke");

// With background colour
$svg = SvgRenderer::dark()->render("\x1b[44m\x1b[37malert:\x1b[0m background highlight");

Ligatures

Code editors render ligatures (β†’, >=, !==, etc.) when font-variant-ligatures: normal is set. Enable it explicitly:

$svg = SvgRenderer::dracula()
    ->withLigatures(true)
    ->render($code);

Language Detection

LanguageDetector provides heuristic detection from content or filename:

use SugarCraft\Freeze\LanguageDetector;

// From content (shebang, then content signatures)
$lang = LanguageDetector::detect($code);        // "php", "bash", "python", ...

// From filename extension
$lang = LanguageDetector::detectFromFilename('script.py');  // "python"
$lang = LanguageDetector::detectFromFilename('foo.php');  // "php"

Detection sources (in priority order):

  • Shebang β€” #!/bin/bash, #!/usr/bin/env node, #!/usr/bin/env php, etc.
  • Filename extension β€” .php, .py, .js, .rb, .sh, .sql, .html, .css, etc.
  • Content signatures β€” language-specific patterns (namespace , <?php, def , const , etc.)

Returns "text" when no match is found.

Themes

SvgRenderer::dark();        // charm-ish #0d1117
SvgRenderer::light();       // #f6f8fa
SvgRenderer::dracula();     // #282a36
SvgRenderer::tokyoNight();  // #1a1b26
SvgRenderer::nord();        // #2e3440

Build a custom theme via the Theme constructor β€” set background / foreground / border / shadow / line-number colour / window-control colours / font family / size / line height.

Demos

Code screenshot

screenshot

ANSI input

ansi-input

Test

cd candy-freeze && composer install && vendor/bin/phpunit

Releases

No releases published

Packages

 
 
 

Contributors

Languages