- How do I install contao/imagine-svg in a Laravel project?
- Run `composer require contao/imagine-svg` in your project root. The package integrates with Imagine, so ensure you also have `imagine/imagine` installed (v1.0.4+ recommended). No additional Laravel-specific setup is needed beyond requiring the package.
- Does contao/imagine-svg support Laravel’s filesystem (Storage facade) for SVG uploads?
- Yes. Use Laravel’s `Storage` facade to upload SVGs (e.g., `Storage::disk('public')->put('image.svg', $file)`), then process them with the package. The package itself doesn’t enforce filesystem rules—it works with any Imagine-compatible input stream.
- Can I use this package to generate SVG thumbnails asynchronously in Laravel?
- Absolutely. Dispatch a queued job (e.g., `OptimizeSvgJob`) to handle heavy SVG transformations. The package’s lightweight design makes it ideal for background processing. Pair it with Laravel’s `shouldQueue()` or Horizon for monitoring.
- What Laravel versions and PHP versions does contao/imagine-svg support?
- The package requires PHP 8.0+ and is framework-agnostic, but it works seamlessly with Laravel 9/10. Tested with Imagine 1.0.4+, which aligns with Laravel’s dependency ecosystem. No Laravel-specific version locks exist, but PHP 8.1+ is recommended for stability.
- How does contao/imagine-svg handle malformed SVGs (e.g., invalid XML namespaces)?
- Version 1.0.4 introduces XML namespace handling and graceful error suppression for invalid resize filters. Malformed SVGs may still fail, but the package now silences exceptions instead of crashing. Validate inputs with `libxml` or `ext-svg` for pre-processing.
- Can I cache processed SVGs in Laravel using this package?
- Yes. Cache transformed SVGs with Laravel’s cache drivers (e.g., `Cache::tags(['svg'])->put('thumbnail', $svgData, 3600)`). The package’s output is Imagine-compatible, so cached results can be reused without reprocessing.
- Are there alternatives to contao/imagine-svg for SVG manipulation in Laravel?
- For basic SVG handling, consider `spatie/image-optimizer` (supports SVG optimization) or `league/html-to-markdown` (for SVG-in-HTML workflows). For advanced transformations, `imagine/imagine` with `ext-gd`/`ext-imagick` is a fallback, but lacks native SVG support.
- How do I test SVG transformations in Laravel’s CI pipeline?
- Use PHPUnit to test SVG operations with mock files or temporary storage. Validate edge cases like complex SVGs (e.g., with `libxml` validation) or animated SVGs. The package’s new error handling reduces flakiness, but test with diverse SVG datasets to catch regressions.
- Will this package work with Laravel Vapor for serverless SVG processing?
- Yes, but ensure your Vapor setup includes PHP extensions like `ext-gd` or `ext-imagick` for raster fallbacks. The package’s lightweight design makes it suitable for serverless, but test cold-start performance for high-volume SVG processing.
- How do I handle SVG aspect ratios or undefined sizes in Laravel?
- Use the package’s `SvgBox` class to check size types: `TYPE_ABSOLUTE`, `TYPE_ASPECT_RATIO`, or `TYPE_NONE`. For undefined sizes, enforce defaults in Laravel (e.g., `config(['svg.default_width' => 800])`) or use Imagine’s `resize()` with aspect ratio constraints.