Weave 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
Webp Convert

Webp Convert Laravel Package

rosell-dk/webp-convert

PHP library for converting JPEG, PNG and other images to WebP. It tries multiple converters (cwebp, vips, Imagick, GD, ffmpeg, cloud APIs) with automatic fallback, so conversions succeed even on limited hosts. Includes quality options, error handling and framework integrations.

Deep Wiki
Context7

webp-convert is a PHP library for converting JPEG, PNG, and GIF images to WebP. It ships with a stack of conversion methods — cwebp, vips, Imagick, Gmagick, GraphicsMagick, FFmpeg, and GD — and automatically falls back through them until one succeeds, so conversion still works on restrictive hosting.

  • Multiple backends with automatic fallback and per-method configuration
  • Control quality, strip metadata, and convert from files, URLs, or binary strings
  • Detailed error reporting and logging for diagnosing failed conversions
  • Optional framework integrations and a simple procedural API
Frequently asked questions about Webp Convert
How do I install and use rosell-dk/webp-convert in a Laravel application?
Install it with composer require rosell-dk/webp-convert. It is PSR-4 autoloaded and needs no service provider or facade, so you can call WebPConvert::convert($source, $destination, $options) directly from a controller, job, or a small service class you wrap around it. The library takes filesystem paths rather than Laravel Storage disks, so resolve the real path first. Most teams put it behind an internal adapter so the rest of the app never touches the procedural API.
Which backends does webp-convert support and how does the automatic fallback work?
It ships converters for the cwebp binary, vips, Imagick, GD, ffmpeg, GraphicsMagick, and several cloud options. When you call convert(), it tries the available backends in order and uses the first one that succeeds, which is why it works on such a wide range of hosts. You can restrict or reorder the backend list through the options array. Be aware that different backends produce different bytes and slightly different visual quality, so the backend is effectively part of your output identity.
Will webp-convert work on shared hosting where exec, proc_open, and shell_exec are disabled?
Yes, but only if a PHP-level backend is usable. Binary converters like cwebp, vips, and GraphicsMagick shell out and will be skipped when those functions are disabled. The fallback then depends on GD compiled with WebP support (imagewebp) or Imagick built with a WebP delegate. The library degrades gracefully rather than throwing immediately, so log or instrument the chosen backend to avoid silent no-op behaviour in production.
How do I convert images to WebP in Laravel when files live on S3 or another object storage disk?
The library is path-based and has no Storage disk awareness, so you must download the original to a local temp file, convert it, then upload the resulting WebP back to the disk. Budget for the extra latency and temp-disk pressure this creates, especially with large PNGs or batch jobs. In most Laravel apps this belongs in a queued job rather than an inline request. If you already have a CDN image transform service, compare the cost of that round trip against doing it yourself.
Why is the converted WebP file sometimes larger than the original JPEG or PNG?
WebP is not universally smaller, particularly for small images or files that were already aggressively optimised. Re-encoding a modest JPEG at a high quality setting can easily produce a bigger file. Compare the resulting byte size against the source and keep the smaller of the two, or skip conversion below a size threshold. A naive always-convert policy can quietly regress your page weight.
How do I control WebP quality and metadata handling with webp-convert?
Quality is set per converter through the options array, typically a 0-100 value passed to each backend, and you can also pick between lossy, lossless, and near-lossless modes where the backend supports them. Metadata such as EXIF and ICC profiles can be preserved or stripped depending on the backend and its options. Because support varies by backend, test your chosen settings against the backend that actually runs in production. Stripping metadata usually saves bytes but may remove orientation or colour profile data you rely on.
Can I use webp-convert alongside intervention/image or spatie/image?
Yes, they do not conflict, but you should not run both for the same concern. A common and pragmatic split is to use Intervention for resizing, cropping, and other geometry work, then hand the resized file to webp-convert for the encode step. That is worthwhile because webp-convert's multi-backend fallback is materially stronger than relying on whatever GD or Imagick happens to expose. Keep a single owner for encoding so behaviour stays predictable.
Does webp-convert support animated WebP, alpha transparency, and lossless mode?
Support is backend-dependent rather than universal. GD has limited capabilities, while cwebp and vips handle lossless and near-lossless modes and preserve alpha well. Animated WebP conversion is only available through specific binaries and is not something every fallback chain can deliver. Decide which of these you actually need before choosing your converter list, and verify it on the exact production host.
Should WebP conversion run on the request path or inside a Laravel queue job?
Conversion is synchronous and CPU-bound, and the library has no queue awareness, so large PNGs can hit memory_limit or max_execution_time if run inline. Push it to a queued job for anything user-generated or batch-oriented, and keep conversion out of the hot request path. If you must convert inline, cache the resulting file and set explicit size and time limits. Track p95 conversion latency so you know when the queue is unavoidable.
Is rosell-dk/webp-convert still maintained, and what are the alternatives?
It is effectively a single-maintainer project, so treat bus factor as a real risk in your dependency register. The upside is an MIT licence and a small, stable procedural surface, which makes forking or wrapping it cheap. Alternatives include Intervention Image's built-in encoding, direct cwebp or vips calls, and edge/CDN transform services such as Cloudflare Polish, imgix, or Cloudinary. If AVIF is on your roadmap, front the encoder with your own adapter interface so you can add or swap backends later.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource