atelier / pattern
Repeatable SVG fill patterns for PHP: dots, stripes, grids, honeycomb, scales, chevron, checker
Requires
- php: >=8.3
- atelier/svg: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Repeatable SVG tiles for fills and strokes, in PHP.
Fill a surface with dots, stripes, grids, or geometric and seeded motifs. Each tile joins with itself so the pattern repeats across the surface.
use Atelier\Pattern\Pattern; $dots = Pattern::dots(spacing: 14, radius: 2.2, stagger: 0.5)->withColor('#f4715c');
Examples from the catalogue: staggered dots and seigaiha.
A pattern is an immutable value. It needs no document to exist and provides a <pattern>
element plus the url(#id) that references it. Add the tile to an Atelier SVG document and
use it as a fill or stroke. For drawings generated for one viewport, see atelier/field.
Style · Catalogue · Errors · Gallery · Documentation
Installation
composer require atelier/pattern
Requires PHP 8.3+ and atelier/svg. Composer installs the package dependencies.
Quick start
<?php declare(strict_types=1); use Atelier\Pattern\Pattern; use Atelier\Pattern\PatternRegistry; use Atelier\Svg\Document; use Atelier\Svg\Dumper\CompactXmlDumper; use Atelier\Svg\Element\Shape\RectElement; require __DIR__.'/vendor/autoload.php'; $dots = Pattern::dots(spacing: 14, radius: 2.2, stagger: 0.5)->withColor('#f4715c'); $document = Document::create(360, 200); (new PatternRegistry($dots))->attachTo($document); $surface = new RectElement(); $surface->setWidth('360')->setHeight('200'); $surface->setAttribute('fill', $dots->fill()); $document->getRootElement()?->appendChild($surface); echo (new CompactXmlDumper())->dump($document);
The example has three steps:
- Create the tile with
Pattern::dots(). - Register it in the document with
PatternRegistry. - Fill the rectangle using
$dots->fill().
The registry places the tile in <defs>. Its identifier is derived from its geometry and style.
Style
Style methods return a new pattern, leaving the original unchanged. The following snippets reuse the imports and autoloader above.
$stripes = Pattern::stripes(spacing: 12, thickness: 4) ->withColor('#c0392b') ->withOpacity(0.4) ->withAngle(30);
The default paint is currentColor and the tile background is transparent. The colour inherits
from the pattern definition's ancestors in <defs>; setting color on the SVG root themes it.
A consuming shape's own color does not recolour that definition. For independent colours,
create patterns with different withColor() values and register each one.
Catalogue
Error handling
Invalid geometry or styling throws Atelier\Pattern\Exception\InvalidArgumentException.
All package exceptions implement Atelier\Pattern\Exception\ExceptionInterface.
Each tile documents its accepted ranges; see Getting started
for validation, identifiers, and seeded output guarantees.
Gallery
From a repository checkout with dependencies installed:
composer gallery
Writes examples/output/index.html with every tile rendered at 300 by 200.
Documentation
- Getting started: install the package and produce a first SVG.
- Illustrated catalogue: choose a tile and explore its parameters.
- Package overview: understand the API and its boundaries.
Read the complete guides and generated illustrations in docs/.
Contributing
Contributions are welcome. Visit the project on GitHub to report a bug, suggest a feature, or open a pull request.
Before submitting code, run:
composer qa composer coverage
Changes to public behaviour need tests and a documentation update. Keep line coverage at 100%. Coverage reporting requires PCOV or Xdebug.
Support
Bug reports, security disclosures, and contribution guidelines are collected at ateliersvg.com/support.
License
Atelier Pattern is released under the MIT License.