$ show KnpLabs/snappy
KnpLabs/snappy is a mature PHP library that provides a clean, object-oriented wrapper around the wkhtmltopdf and wkhtmltoimage command-line tools. It enables generation of PDF documents and image thumbnails from HTML content or URLs. The library is architected around an abstract base class (AbstractGenerator) that implements the template method pattern, handling command construction, process execution via Symfony Process, temporary file management, and PSR-3 logging. Concrete subclasses (Pdf and Image) define their own option sets and handle special cases like converting inline HTML strings to temporary files for header/footer content. The library is widely used in the PHP ecosystem, with dedicated Symfony and Laravel integration bundles. It requires PHP 8.1+ and depends only on symfony/process and psr/log, making it lightweight and easy to integrate.
The LLM identified 1 files worth highlighting for reuse:
The core abstract class that encapsulates the entire workflow of generating media files via an external binary. It defines a template method (generate) that orchestrates output preparation, command building, process execution, and output validation. It provides reusable infrastructure for option management (addOption, setOption, mergeOptions), temporary file creation with automatic cleanup, and PSR-3 logging integration. The buildCommand method constructs shell commands with proper escaping and handles various option types (booleans, arrays, associative arrays). This class is highly reusable as a base for any PHP wrapper that needs to execute a command-line tool with options and manage temporary files.