Download the PHP package weldist/spatie-medialibrary-webp-downloader without Composer

On this page you can find all versions of the php package weldist/spatie-medialibrary-webp-downloader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package spatie-medialibrary-webp-downloader

weldist/spatie-medialibrary-webp-downloader

Tests PHP Laravel

A WebP-converting Downloader for spatie/laravel-medialibrary.

A weld.ist project.

Unofficial plugin. Not affiliated with Spatie.

The Problem

spatie/laravel-medialibrary's addMediaFromUrl() (and friends) downloads a remote file and stores it byte-for-byte as it arrived:

That is wasteful for the common case — user avatars, article hero images, product photos pulled from a supplier feed. WebP routinely shaves 25–35% off a JPEG and far more off a PNG at the same visual quality, but media-library exposes no hook to transcode on ingest:

The Solution

This package ships a drop-in Downloader that re-encodes images to WebP while they are being downloaded, before media-library ever writes the original to disk:

Requirements

Installation

The package auto-discovers a single service provider — the file-name correction listener described below. It does not bind the downloader for you; that is a one-line edit to your own config so you stay in control of whether it is active.

Setup

Edit config/media-library.php and swap the downloader binding:

That's it. From now on every addMediaFromUrl() call passes through the WebP converter.

Image Driver

The driver is chosen automatically from Spatie's existing config and forwarded to Spatie\Image\Image::useImageDriver():

The required PHP extension (ext-gd / ext-imagick) — or libvips for vips — must be loaded.

Tuning

WebpDownloader accepts two optional constructor arguments — both auto-resolved via the container with sensible defaults:

Argument Default Meaning
quality 85 WebP quality (0–100)
skipMimes ['image/svg+xml', 'image/gif'] MIME types that bypass conversion

To override, bind a custom instance in your own service provider:

Why is SVG always skipped, and GIF skipped by default? Rasterising an SVG to WebP throws away the thing that makes it an SVG, so it is never converted. GD flattens animated GIFs to a single frame; drop image/gif from skipMimes only if you are on Imagick and want animated WebP output.

Automatic File Name Correction

WebpDownloaderServiceProvider is auto-discovered. It listens for Spatie's MediaHasBeenAddedEvent — fired after the downloaded bytes land on disk — and, in lock-step, renames the on-disk file to .webp and updates the row's file_name via saveQuietly() when all of the following hold:

So obama.jpg → obama.webp (basename preserved, extension swapped). Disk uploads of unrelated formats, and media added while a different downloader is configured, are never touched. The listener is idempotent — a re-fired event finds the source already renamed and the column already .webp, so it is a no-op.

Why a listener instead of usingFileName(...)? media-library decides the on-disk name from the URL basename (photo.jpg) inside FileAdder::processMediaItem, after the model's creating event. Mutating file_name earlier leaves the row pointing at .webp while the file sits at .jpg → 404. Renaming after MediaHasBeenAddedEvent is the first point where both the file and the row can be fixed together.

To opt out, set extra.laravel.dont-discover in your root composer.json and rename manually with ->usingFileName(...).

Converting Existing Media

For projects that already have thousands of JPEGs/PNGs on disk, the package ships an Artisan command — media-library:webp-convert — that walks the media table and re-encodes rows in place.

1. Preview first. A dry run reports which rows would be converted and touches nothing:

2. Run the conversion. Sync mode for small libraries, --queue for large ones:

3. Regenerate conversions. Existing thumbnails and responsive images are now stale because their source changed — the command prints a reminder when it finishes:

For each Media row the command:

  1. Skips image/webp, non-image MIME types, and entries in the configured WebpDownloader skipMimes
  2. Reads the file via the row's own disk and the PathGenerator resolved by Spatie (custom path generators are honoured automatically)
  3. Re-encodes to WebP using media-library.image_driver and the quality from the container-bound WebpDownloader instance
  4. Writes the new .webp file, then updates file_name, mime_type, and size via saveQuietly(), then deletes the original — in that order, so a crash never leaves a row pointing at a deleted file

It is safe to re-run: already-WebP rows hit the skip guard. Both modes support --dry-run (queue + dry-run just reports what would be dispatched).

Options:

Option Description
--collection= Limit to one media collection
--model= Limit to one owning model class
--since= Only media added on or after this date
--id-from= / --id-to= Restrict to an id range — designed for sharded parallel runs (two terminals split the range and dispatch independently)
--chunk= chunkById() batch size for large tables
--queue Dispatch one ConvertMediaToWebpJob per row instead of converting inline
--queue-connection= / --queue-name= Target connection / queue for --queue
--dry-run Report what would be converted (or dispatched) without changing anything

Testing

License

This package is open-sourced software licensed under the MIT license.


All versions of spatie-medialibrary-webp-downloader with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/support Version ^12.0|^13.0
spatie/image Version ^3.0
spatie/laravel-medialibrary Version ^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package weldist/spatie-medialibrary-webp-downloader contains the following files

Loading the files please wait ...