HTML to image rendering for PHP, powered by Rust and Takumi. Generate Open Graph images and more from HTML/CSS without headless browser overhead.
tbd
| Input | Behaviour |
|---|---|
<style> tags |
CSS extracted and applied as a stylesheet |
Inline style="..." |
Promoted to a generated CSS class rule |
<img src="..."> |
Local paths and data URIs supported |
CSS background-image: url(...) |
Local paths and data URIs supported |
<br> |
Rendered as a newline |
<html>, <head>, <body> |
Transparent wrappers, stripped |
| All other elements | Rendered as Takumi container nodes (class, id, tagName forwarded) |
Takumi's layout engine supports Flexbox, CSS Grid, tw Tailwind utility classes, and CSS
animations.
composer require avvertix/html-shotRequirements
- PHP 8.2 or higher
- FFI extension enabled
ext-ffi| enabled (ffi.enable = trueinphp.ini) |
tbd
git clone https://github.com/avvertix/html-shot.git
cd html-shot
# Install PHP dependencies
composer install
# Build the Rust library
cd rust && cargo build --releaseThe Rust library must be compiled for your target platform. A pre-built binary is attached to each GitHub release or you can build your own.
cd vendor/avvertix/html-shot/rust
cargo build --releaseThen copy the compiled library to the lib/ directory at the package root:
| Platform | Source | Destination |
|---|---|---|
| Linux | target/release/libhtml_shot.so |
../lib/libhtml_shot.so |
| macOS | target/release/libhtml_shot.dylib |
../lib/libhtml_shot.dylib |
| Windows | target/release/html_shot.dll |
../lib/html_shot.dll |
The C header is auto-generated by cbindgen and written to include/html_shot.h during the build.
Check whether FFI is active:
php -m | grep FFIIf it is not listed, add the following to your php.ini and restart PHP-FPM / your web server:
extension=ffi
ffi.enable=trueContributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE file for details.
Powered by Takumi