- How do I install this package in a Laravel project?
- Run `composer require codebuds/webp-converter` to install the package. No additional Laravel-specific setup is required, though you may need to enable PHP’s GD extension in your `php.ini` file.
- Does this package work with Laravel’s Storage facade for file handling?
- Yes, you can use Laravel’s Storage facade to pass file paths or uploads. For example, use `$request->file('image')->getRealPath()` with the `createWebpImage()` method to convert uploaded files.
- What Laravel versions does this package support?
- This package is framework-agnostic but tested with PHP 7.4+. It works seamlessly with Laravel 8+ and Symfony 5+, leveraging Laravel’s filesystem and request handling features.
- How can I handle large batches of image conversions efficiently?
- For high-throughput environments, dispatch conversions as Laravel queue jobs using `dispatch()` with `WebPConverter::createWebpImage()`. This offloads processing to background workers like Horizon.
- What happens if GD is not installed on the server?
- The package will throw an exception if GD is missing. Document this requirement in your deployment checklist or provide a fallback (e.g., Imagick or an external API) for environments where GD isn’t available.
- Can I customize the output filename or path for converted WebP images?
- Yes, use the `filename`, `filenameSuffix`, and `savePath` options in the `createWebpImage()` method. For example, set `'filename' => 'converted_' . $userId` to generate unique filenames.
- How do I handle errors like invalid file types or missing dependencies?
- Wrap the `createWebpImage()` call in a `try-catch` block. Exceptions include invalid file types, missing GD, or invalid options. Log these errors with context (e.g., file path) for debugging.
- Does this package support async processing or Laravel Queues?
- While the package itself is synchronous, you can integrate it with Laravel Queues by dispatching conversions as jobs. This prevents blocking requests during high-traffic periods.
- What are the supported input formats and quality options?
- The package converts JPEG, PNG, GIF, and BMP to WebP. Use the `quality` option (1–100) to control compression. For example, `['quality' => 80]` sets 80% quality.
- Are there alternatives to this package for Laravel?
- Alternatives include `rosell-dk/webp-convert` (supports more formats) or `intervention/image` (feature-rich but heavier). This package is lightweight (~100 lines) and ideal for GD-based WebP conversions.