- How do I install phenx/php-svg-lib in a Laravel application?
- Install it with Composer by running composer require phenx/php-svg-lib; the library is framework-agnostic, so no service provider or config file is needed. If you already use Dompdf, it usually arrives automatically as a transitive dependency, so check composer.lock before adding it explicitly. Confirm the installed version is the same one Dompdf expects so you do not end up with two divergent copies.
- What is phenx/php-svg-lib actually used for?
- It parses SVG XML into an internal object model and draws those objects onto a pluggable Surface backend. It is the SVG engine behind Dompdf, so its most common use is embedding vector graphics in generated PDFs without shelling out to external tools. It is not an image server or a full SVG rendering platform; output quality depends entirely on the Surface you supply.
- Does phenx/php-svg-lib work without Dompdf?
- Yes. The library only parses SVG and emits drawing operations, so any backend can consume them once you implement the Surface interface. Dompdf simply ships one well-tested Surface implementation. Expect to write and maintain your own adapter, plus contract tests, for any other target.
- Which PHP and Laravel versions does php-svg-lib support?
- The package is framework-agnostic and has no Laravel-specific dependency, so Laravel compatibility is really a question of the PHP constraint declared in its composer.json. Check that constraint against your application runtime before upgrading, and make sure the XML and DOM extensions are available. If you rely on it through Dompdf, pin both packages together and validate their combined upgrade path.
- Can I use php-svg-lib to convert an SVG to PNG or JPEG?
- Not out of the box. The package produces drawing operations rather than pixels, so raster output requires a Surface implementation backed by GD or Imagick plus your own handling of antialiasing, fonts and effects. Many teams use a headless browser or Imagick's librsvg-based SVG support instead when pixel-accurate raster fidelity matters.
- How do I implement a custom Surface for php-svg-lib?
- Create a class implementing the Surface interface and route each draw call to your target canvas, PDF writer or graphics API. Start with a narrow feature set such as paths, basic shapes, solid fills and strokes, then add gradients, transforms and text as your SVG corpus demands. Contract tests that compare emitted operations against golden output keep the adapter safe to evolve.
- Why does my SVG render incorrectly or incompletely in Dompdf?
- phenx/php-svg-lib covers a practical subset of SVG rather than the full browser feature set, so filters, masks, clip paths, nested CSS and advanced gradient or font features often degrade or disappear. Text rendering is especially dependent on the fonts you make available, since there is no browser-grade font shaping. Simplify the SVG, convert text to paths, or flatten effects upstream to get predictable results.
- Is it safe to render user-uploaded SVG with phenx/php-svg-lib?
- SVG is XML, so untrusted input carries the usual XML risks, including external entity expansion and denial of service via huge or deeply nested documents. Validate and sanitise uploads, disable external entity and remote resource loading, enforce file size and element limits, and treat any referenced URLs as untrusted. Run rendering under constrained memory and time limits, and reject input the library cannot fully handle.
- What license does phenx/php-svg-lib use and is it fine for commercial products?
- The package is distributed under LGPL-3.0, which is generally workable when you consume it unmodified as a separate Composer library. Modifying it, statically bundling it, or shipping it inside a distributed appliance can trigger additional obligations, so have legal review those scenarios. Keep the license and copyright notices intact.
- What are the alternatives to phenx/php-svg-lib for SVG in PHP?
- For raster output, Imagick with librsvg, headless Chrome via Puppeteer, or resvg bindings deliver far higher fidelity than a PHP parser. For PDF vector work, Dompdf plus php-svg-lib remains the established PHP path, while PDF libraries with native SVG support are another option. Choose based on whether you need browser-accurate pixels or just reasonable vector rendering inside a generated document.