Repository navigation
2.0.0
The first stable 2.0 release. This is a ground-up rewrite of the rendering
pipeline with a new Generator entry point, composable backgrounds, accurate
font metrics, and multi-language text support. It consolidates everything from
2.0.0-beta.1 through 2.0.0-beta.4.
Upgrading from 1.x? This release is not backward compatible — see
Breaking Changes below. Install withcomposer require yilanboy/preview:^2.0.
💥 Breaking Changes
- Minimum PHP is now
^8.4(was^8.2). Image\Builderis replaced byGeneratoras the main entry point — an API
rename, not backward compatible.Color\Converteris replaced by a top-levelColorConverterwith static
methods; dependency injection removed.- The
backgroundColorshortcut is removed. Backgrounds are now configured
via dedicated background classes (Solid,Gradient,Image). - Background interfaces moved into a
Contractsnamespace (Contracts\Background). - Text handling reworked around a new
TextBlockvalue object and an internal
layout engine.
✨ Added
- Composable backgrounds (
Yilanboy\Preview\Canvas):Solid— a flat color.Gradient— two-color interpolation with aGradientDirectionenum
(Vertical,Horizontal,Diagonal).Image— a bitmap background with anImageFitenum (Cover,Contain,
Stretch,Tile), configurableopacity, and atintcolor.
TextBlockvalue object (immutable,final readonly) for title and
description text, withFont,FontSize,Alignment,LineHeight, and
Positionenums. Title and description stack without overlapping.- Custom TrueType fonts — pass a
.ttffile path, validated on construction
(OpenType / non-TTF files are rejected). - Multi-language text rendering for Traditional Chinese, Simplified Chinese,
and Japanese, with appropriate word/character wrapping. - Custom canvas sizes and font sizes —
Generator::dimensions(int, int)and a
custom integer pixelFontSize, both validated (InvalidInputbelow1). Size,Margin, andFormatenums for canvas presets and output encoding.- Typed exceptions in a new
Exceptionsnamespace:InvalidInputand
RenderFailure, both implementing thePreviewExceptionmarker interface.
Backward compatible — they still extend the SPL exceptions the library threw
before, so existing catch blocks keep working. - Color validation enforced at construction across all color-accepting types
viaColorConverter::isValidColor()(named colors or hex).
🛠 Improved & Fixed
- Accurate line height derived directly from the font's
head/hheasfnt
tables (via a newLineMetricsvalue object) instead of glyph bounding-box
probing. - More robust font parsing — sfnt tables are validated and binary unpacking
errors are handled gracefully, throwingRenderFailureon corrupt font files. - Faster rendering — text lines are measured once during wrapping and reused
at placement;Imagebackgrounds decode the source file once and cache the
bitmap.
Full Changelog: 1.0.1...2.0.0