vierwd/svg-inliner
A Laravel package for inlining SVG images directly into your HTML, letting you style and animate them with CSS and control their colors. Useful for icons and illustrations where external image references would block styling. Lightweight and easy to integrate.
<svg> vs. <img src> vs. sprite sheet vs. icon font. This package pushes you toward inlining, which is the only one of the four that lets CSS in the parent document style the SVG's internals. That single technical fact drives several downstream product decisions (theming, dark mode, hover/active states) that are expensive to reverse once an icon set ships as <img> tags or a font.fill="currentColor" and CSS custom properties, so a tenant-branded or dark-mode theme becomes a CSS change rather than an asset re-export. If the roadmap includes multi-brand or per-customer theming, this is a gating technical choice, not an implementation detail.role="img", <title>, aria-hidden, and focusable="false" at the call site; <img> cannot be styled or annotated from the parent document. If the roadmap includes an accessibility audit or public-sector procurement, this reduces remediation scope.Adopt (or, more likely, vendor) when:
?raw imports through Vite, or hand-rolling a Blade component — costs more than the package saves you this sprint.Look elsewhere (or write it yourself) when:
<script>, onload= handlers, and <foreignObject>. If any SVG crosses a trust boundary — uploads, CMS content, third-party logo packs — pair this with enshrined/svg-sanitize or sanitize at ingestion, and treat this package as the emitter only. Do not assume it sanitizes; verify before shipping.?raw imports or an svgo pipeline inline SVGs at build time with zero runtime cost and zero PHP dependency. If the icon set is static, build-time inlining is strictly better: no filesystem reads per request, no cache-key concerns.<use> references. Different problem, different tool.For executives (one paragraph): We evaluated a small open-source utility for embedding SVG icons directly into server-rendered pages. The capability is real and it supports decisions we are already making — inline SVG is what makes dark mode, per-customer branding, and accessible icons cheap to implement instead of expensive to retrofit. But the package itself is a ~50-line helper with a single maintainer, one star, and no release since 2022. Recommendation: adopt the pattern, not the dependency. We copy the utility into our codebase under its MIT license, add tests and input sanitization, and own it outright. Cost is roughly one engineer-day; it removes a single-vendor risk while preserving the product benefits. This is a low-stakes, reversible decision — but it should be made deliberately rather than by a composer require that quietly becomes load-bearing.
For engineering: Treat this as a code sample, not a library. Vendor it, pin the PHP version in CI, wrap the file-resolution path so it cannot escape the assets root (path traversal), and add a sanitization step in front of any SVG that is not authored in-repo. Add a memoization cache so repeated icons in a loop do not re-hit disk. Write the three or four tests the package does not ship with. If the wrapper ends up larger than the original, that is the expected outcome and still cheaper than an unmaintained upstream.
For design and content: Inline SVG means icons respond to currentColor and CSS variables — ask for theming and state variations now, because switching from <img> to inline later touches every template.
How can I help you explore Laravel packages today?