Skip to content

2.0.0

Choose a tag to compare

@yilanboy yilanboy released this 15 Jun 15:24
· 21 commits to main since this release

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 with composer require yilanboy/preview:^2.0.

💥 Breaking Changes

  • Minimum PHP is now ^8.4 (was ^8.2).
  • Image\Builder is replaced by Generator as the main entry point — an API
    rename, not backward compatible.
  • Color\Converter is replaced by a top-level ColorConverter with static
    methods; dependency injection removed.
  • The backgroundColor shortcut is removed. Backgrounds are now configured
    via dedicated background classes (Solid, Gradient, Image).
  • Background interfaces moved into a Contracts namespace (Contracts\Background).
  • Text handling reworked around a new TextBlock value object and an internal
    layout engine.

✨ Added

  • Composable backgrounds (Yilanboy\Preview\Canvas):
    • Solid — a flat color.
    • Gradient — two-color interpolation with a GradientDirection enum
      (Vertical, Horizontal, Diagonal).
    • Image — a bitmap background with an ImageFit enum (Cover, Contain,
      Stretch, Tile), configurable opacity, and a tint color.
  • TextBlock value object (immutable, final readonly) for title and
    description text, with Font, FontSize, Alignment, LineHeight, and
    Position enums. Title and description stack without overlapping.
  • Custom TrueType fonts — pass a .ttf file 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 pixel FontSize, both validated (InvalidInput below 1).
  • Size, Margin, and Format enums for canvas presets and output encoding.
  • Typed exceptions in a new Exceptions namespace: InvalidInput and
    RenderFailure, both implementing the PreviewException marker 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
    via ColorConverter::isValidColor() (named colors or hex).

🛠 Improved & Fixed

  • Accurate line height derived directly from the font's head/hhea sfnt
    tables (via a new LineMetrics value object) instead of glyph bounding-box
    probing.
  • More robust font parsing — sfnt tables are validated and binary unpacking
    errors are handled gracefully, throwing RenderFailure on corrupt font files.
  • Faster rendering — text lines are measured once during wrapping and reused
    at placement; Image backgrounds decode the source file once and cache the
    bitmap.

Full Changelog: 1.0.1...2.0.0