PHPackages                             sugarcraft/candy-freeze - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. sugarcraft/candy-freeze

ActiveLibrary[CLI &amp; Console](/categories/cli)

sugarcraft/candy-freeze
=======================

PHP port of charmbracelet/freeze — render code or terminal output to SVG screenshots with macOS-style window controls, drop shadow, line numbers, and inline ANSI SGR colour parsing.

10PHP

Since Jun 29Pushed 1mo agoCompare

[ Source](https://github.com/sugarcraft/candy-freeze)[ Packagist](https://packagist.org/packages/sugarcraft/candy-freeze)[ RSS](/packages/sugarcraft-candy-freeze/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![candy-freeze](.assets/icon.png)](.assets/icon.png)

CandyFreeze
===========

[](#candyfreeze)

[![CI](https://github.com/detain/sugarcraft/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/detain/sugarcraft/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/223e3f94651257bb039221c3e3bb699171cc977a383a7a2ed56fdd1bbd180780/68747470733a2f2f636f6465636f762e696f2f67682f64657461696e2f737567617263726166742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f666c61673d63616e64792d667265657a65)](https://app.codecov.io/gh/detain/sugarcraft?flags%5B0%5D=candy-freeze)[![Packagist Version](https://camo.githubusercontent.com/032607066003821f26bb2b38bcaa2bbcb2d59433f498b1ced6498946ac1254e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737567617263726166742f63616e64792d667265657a653f6c6162656c3d7061636b6167697374)](https://packagist.org/packages/sugarcraft/candy-freeze)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/e78ffc83837c0d12647811a7fd1910c3cbeae04988de94bb4fd5b67e0874696a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135382e312d3838393262662e737667)](https://www.php.net/)

[![demo](.vhs/screenshot.gif)](.vhs/screenshot.gif)

PHP port of [charmbracelet/freeze](https://github.com/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
---

[](#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 ` — write SVG to a file instead of stdout.

Library
-------

[](#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 `` segments in the output. Background colours are rendered as per-segment `` 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
---------

[](#ligatures)

Code editors render ligatures (→, &gt;=, !==, etc.) when `font-variant-ligatures: normal` is set. Enable it explicitly:

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

Language Detection
------------------

[](#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 `, `
