Search by

sushilk / svg

CodeWithSushil

A modern, secure and fluent PHP library for generating SVG documents.

Package info

github.com/CodeWithSushil/svg-generator

pkg:composer/sushilk/svg

Fund package maintenance!

CodeWithSushil

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 2

v1.0.0 2026-08-29 11:54 UTC

This package is auto-updated.

Last update: 2026-09-11 14:23:34 UTC


README

PHP Supabase Latest Version Total Downloads License

A modern, secure and fluent PHP 8.4+ library for generating SVG documents.

Installation

composer require sushilk/svg

Quick start

<?php

require __DIR__ . '/vendor/autoload.php';

use Svg\Svg;

$svg = new Svg(800, 500);

$svg->viewBox(0, 0, 800, 500)
    ->title('Lilac SVG')
    ->description('Generated with lilac/svg');

$gradient = $svg->defs()
    ->linearGradient('background')
    ->from(0, 0)
    ->to(1, 1);

$gradient
    ->stop(0, '#2563eb')
    ->stop(1, '#7c3aed');

$svg->rect(0, 0, 800, 500)
    ->fillUrl('background')
    ->radius(30);

$svg->circle(400, 220, 100)
    ->fill('#fff');

$svg->text('Lilac SVG', 400, 380)
    ->fontSize(52)
    ->fontWeight(700)
    ->textAnchor('middle')
    ->fill('#fff');

echo $svg->render(true);

Features

  • Fluent SVG API
  • Rectangles, circles, ellipses, lines, paths, polygons and polylines
  • Text and tspans
  • Groups and transforms
  • Gradients, patterns, markers, masks and clipping paths
  • SVG filters
  • SVG animation elements
  • XML escaping by default
  • Accessibility metadata
  • PHP 8.4+
  • PSR-4 autoloading
  • PHPUnit and PHPStan support

License

MIT. See LICENSE.