Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Svg Laravel Package

meyfa/php-svg

Lightweight PHP library to create, read, and manipulate SVGs. Build SVG documents programmatically, edit shapes and attributes via a DOM-like API, and export clean SVG/XML. Handy for generating icons, diagrams, and server-side graphics without external dependencies.

View on GitHub
Deep Wiki
Context7

Vector graphics (SVG) library for PHP

Frequently asked questions about Php Svg
Can I use meyfa/php-svg to generate dynamic charts or graphs in Laravel?
Yes, the package provides an object-oriented API for building SVG elements like paths, shapes, and text, making it perfect for generating charts or graphs programmatically. You can dynamically populate data from Laravel models or queries and render the SVG output directly in Blade templates or API responses.
How do I install meyfa/php-svg in a Laravel project?
Install via Composer with `composer require meyfa/php-svg`. No additional Laravel-specific setup is required, though you may want to register it as a service provider or create a facade for cleaner Blade/Controller usage. The package is dependency-free and works out of the box.
Does meyfa/php-svg support modifying existing SVG files?
Yes, the library allows you to parse and manipulate existing SVG markup using a DOM-like structure. This is useful for updating legacy SVGs, applying dynamic changes, or A/B testing variations without starting from scratch.
Will this package work with Laravel 10+ and PHP 8.1+?
The package is designed to be lightweight and backward-compatible, but always check the latest version’s `composer.json` for explicit PHP/Laravel version requirements. As of now, it supports modern PHP versions and integrates seamlessly with Laravel’s ecosystem.
Can I cache generated SVGs in Laravel for better performance?
Absolutely. Use Laravel’s `Cache` facade or `File` storage to cache generated SVGs. For example, store the SVG markup as a string in Redis or save it as a file in `storage/app/svg/`. This avoids regenerating the same SVG on every request.
How do I integrate SVG generation into Laravel Queues for heavy operations?
Create a job class (e.g., `GenerateSvgJob`) that uses the library to build the SVG, then dispatch it via `GenerateSvgJob::dispatch($data)`. Laravel’s queue system will handle the async processing, and you can return a cached or placeholder SVG immediately.
Are there security risks when generating SVGs with user input?
Yes, user-generated content in SVGs can pose XSS risks. Always sanitize dynamic text or attributes using `htmlspecialchars()` or Laravel’s `Str::of()` helper. Avoid embedding untrusted SVG markup directly in responses.
Can I use meyfa/php-svg to create reusable SVG components in Blade?
Yes, you can create Blade components or directives to encapsulate SVG generation logic. For example, `@svg('badge', ['text' => 'New'])` could render a dynamic badge SVG. This keeps your templates clean and reusable.
What are the alternatives to meyfa/php-svg for Laravel SVG generation?
Alternatives include `svg` (by League), which is more feature-rich but heavier, or JavaScript libraries like `svg.js` for client-side generation. For Laravel-specific needs, consider `spatie/svg` if you need advanced features like SVG uploads or transformations.
How do I test SVG generation in Laravel with PHPUnit or Pest?
Mock the SVG generation logic in your tests by creating isolated test cases for individual elements (e.g., circles, paths). Use assertions to verify the output markup matches expectations. For integration tests, simulate API requests or Blade rendering to ensure SVGs are generated correctly.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi