PHP-Layers is a OOP library for creating images in PHP.
It adds powerful layering functionality known from image editors, while staying intuitive and simple to use.
- PHP 8.0+
- GD2 extension
- Stacking of images, with transparency
- Importing and exporting images - supports classic and modern formats (PNG, JPEG, WebP, AVIF)
- Convinience functions for drawing
- Rich text
The project should be considered unstable for now, as I'm refactoring the code from an unhinged mess I made 10 years ago.
Here is a code for adding watermark to an image:
use Naomai\PHPLayers\Image;
// import image as background
$layersImg = Image::createFromFile("stroller.jpg");
// create a watermark layer from file, and move it to bottom left corner
$watermarkLayer = $layersImg->newLayer()->importFromFile("lg_watermark.png");
$watermarkLayer
->selectSurface()
->move(anchor: "bottom left")
->apply();
// export the image, and include it in the HTML file
$dataUrl = $layersImg->export()->asDataUrl("webp");
echo "<img src=\"".htmlspecialchars($dataUrl)."\"/><br/>";
Previously developed as GDWrapper, was powering a rendering engine for Map Previews in Unreal Tournament Stats Tracker:
Phancake includes two additional methods for adding text to your images.
Those features need heavy refactoring, and will be documented when they become stable.
Capability to render formatted blocks of text. Change font, make it bold, mark it red in the middle of paragraph. We take care of the text flow.
Spread different text labels, so they don't overlap. Useful for auto-generated images with tooltips.